Submission #961004

#TimeUsernameProblemLanguageResultExecution timeMemory
961004hirayuu_ojLinear Garden (IOI08_linear_garden)C++17
0 / 100
58 ms65536 KiB
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define all(x) x.begin(),x.end() using ll=long long; const ll INF=1LL<<60; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin>>N>>M; string S; cin>>S; int dp[1000010][5][5][2]; rep(i,N+1){ rep(j,5){ rep(k,5){ dp[i][j][k][0]=0; dp[i][j][k][1]=0; } } } dp[0][2][2][1]=1; rep(i,N){ rep(j,5){ rep(k,5){ dp[i][j][k][0]%=M; dp[i][j][k][1]%=M; if(k+1<5){ dp[i+1][min(j+1,2)][k+1][0]+=dp[i][j][k][0]; if(S[i]=='P'){ dp[i+1][min(j+1,2)][k+1][0]+=dp[i][j][k][1]; } else{ dp[i+1][min(j+1,2)][k+1][1]+=dp[i][j][k][1]; } } if(j-1>=0){ dp[i+1][j-1][max(2,k-1)][0]+=dp[i][j][k][0]; if(S[i]=='P'){ dp[i+1][j-1][max(2,k-1)][1]+=dp[i][j][k][1]; } } } } } int ans=0; rep(i,5){ rep(j,5){ ans+=dp[N][i][j][0]; ans+=dp[N][i][j][1]; ans%=M; } } cout<<ans<<"\n"; }
#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...