제출 #896729

#제출 시각아이디문제언어결과실행 시간메모리
896729LCJLYLinear Garden (IOI08_linear_garden)C++14
100 / 100
105 ms10232 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl; typedef pair<int,int>pii; typedef pair<pii,pii>pi2; int n,mod; int arr[1000005]; //vector<int>memo[3][3][2]; //int dp(int index, int lotus, int pap, bool bound){ //if(index==n) return 1; //if(memo[lotus][pap][bound][index]!=-1) return memo[lotus][pap][bound][index]; //int ans=0; //if(bound){ //for(int x=1;x<=arr[index];x++){ //int hold=lotus; //int hold2=pap; //if(x==1){ //hold++; //hold2=max(0LL,hold2-1); //} //else{ //hold2++; //hold=max(0LL,hold-1); //} //if(hold>2||hold2>2) continue; //ans=(ans+dp(index+1,hold,hold2,x==arr[index]))%mod; //} //} //else{ //for(int x=1;x<=2;x++){ //int hold=lotus; //int hold2=pap; //if(x==1){ //hold++; //hold2=max(0LL,hold2-1); //} //else{ //hold2++; //hold=max(0LL,hold-1); //} //if(hold>2||hold2>2) continue; //ans=(ans+dp(index+1,hold,hold2,false))%mod; //} //} //return memo[lotus][pap][bound][index]=ans; //} void solve(){ cin >> n >> mod; string s; cin >> s; for(int x=0;x<n;x++){ if(s[x]=='L') arr[x]=1; else arr[x]=2; } int dp[2][3][3][2]; memset(dp,0,sizeof(dp)); dp[0][0][0][1]=1; int counter=0; for(int index=0;index<=n;index++){ for(int lotus=0;lotus<3;lotus++){ for(int pap=0;pap<3;pap++){ for(int bound=0;bound<2;bound++){ if(index==n){ counter=(counter+dp[0][lotus][pap][bound])%mod; continue; } if(bound){ for(int x=1;x<=arr[index];x++){ int hold=lotus; int hold2=pap; if(x==1){ hold++; hold2=max(0LL,hold2-1); } else{ hold2++; hold=max(0LL,hold-1); } if(hold>2||hold2>2) continue; dp[1][hold][hold2][(x==arr[index])]=(dp[1][hold][hold2][(x==arr[index])]+dp[0][lotus][pap][bound])%mod; } } else{ for(int x=1;x<=2;x++){ int hold=lotus; int hold2=pap; if(x==1){ hold++; hold2=max(0LL,hold2-1); } else{ hold2++; hold=max(0LL,hold-1); } if(hold>2||hold2>2) continue; dp[1][hold][hold2][0]=(dp[1][hold][hold2][0]+dp[0][lotus][pap][bound])%mod; } } } } } for(int lotus=0;lotus<3;lotus++){ for(int pap=0;pap<3;pap++){ for(int bound=0;bound<2;bound++){ dp[0][lotus][pap][bound]=dp[1][lotus][pap][bound]; dp[1][lotus][pap][bound]=0; } } } } cout << counter; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("out.txt", "w", stdout); int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...