Submission #961005

#TimeUsernameProblemLanguageResultExecution timeMemory
961005hirayuu_ojLinear Garden (IOI08_linear_garden)C++17
100 / 100
241 ms2296 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; using table=array<array<array<int,2>,5>,5>; table dp; rep(i,5){ rep(j,5){ dp[i][j][0]=0; dp[i][j][1]=0; } } dp[2][2][1]=1; rep(i,N){ table ndp; rep(j,5){ rep(k,5){ ndp[j][k][0]=0; ndp[j][k][1]=0; } } rep(j,5){ rep(k,5){ dp[j][k][0]%=M; dp[j][k][1]%=M; if(k+1<5){ ndp[min(j+1,2)][k+1][0]+=dp[j][k][0]; if(S[i]=='P'){ ndp[min(j+1,2)][k+1][0]+=dp[j][k][1]; } else{ ndp[min(j+1,2)][k+1][1]+=dp[j][k][1]; } } if(j-1>=0){ ndp[j-1][max(2,k-1)][0]+=dp[j][k][0]; if(S[i]=='P'){ ndp[j-1][max(2,k-1)][1]+=dp[j][k][1]; } } } } dp=move(ndp); } int ans=0; rep(i,5){ rep(j,5){ ans+=dp[i][j][0]; ans+=dp[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...