Advertisement
hsiuyee

Problem E. Express Lines

Jun 8th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define int long long
  5. #define fastio ios::sync_with_stdio(false),cin.tie(0);
  6. #define pll pair<ll,ll>
  7. #define F first
  8. #define S second
  9. #define pb push_back
  10. #define ppb pop_back()
  11. #define mkp make_pair
  12. #define sz(a) (ll)a.size()
  13.  
  14. const ll MAXN=1e6+5;
  15. const ll INF=1e18;
  16. const ll MOD=998244353;
  17.  
  18. ll N,K,dp[2][MAXN][2]; // 編號、當前顏色 0:黑色
  19.  
  20. void solve(){
  21.     while(cin>>N>>K){
  22.         dp[0][0][0]=dp[1][0][1]=1;
  23.         for(ll i=0;i<2;i++){ // 是否 1 st stop 有停
  24.             for(ll j=1;j<N;j++){
  25.                 dp[i][j][0]=dp[i][j-1][1]%K;
  26.                 dp[i][j][1]=(dp[i][j-1][1]+dp[i][j-1][0])%K;
  27.             }
  28.         }
  29.         cout<<((dp[0][N-1][1]+dp[1][N-1][0]+dp[1][N-1][1]-1-N)%K+K)%K<<'\n';
  30.         // 都不選、只選一站
  31.     }
  32. }
  33.  
  34. signed main(){
  35.     fastio 
  36.     freopen("express.in","r",stdin);
  37.     freopen("express.out","w",stdout);
  38.     // ll T;
  39.     // cin>>T;
  40.     solve();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement