제출 #99530

#제출 시각아이디문제언어결과실행 시간메모리
99530figter001Linear Garden (IOI08_linear_garden)C++17
90 / 100
142 ms66560 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int nax = 1e6+50; int n,mod; string s; int dp[nax][3][3]; int calc(int idx,int a,int b){ if(a < 0)a = 0; if(b < 0)b = 0; if(a == 3)return 0; if(b == 3)return 0; if(idx == n) return 1; int &ret = dp[idx][a][b]; if(ret != -1) return ret; ret = 0; ret = (calc(idx+1,a+1,b-1) + calc(idx+1,a-1,b+1)) % mod; return ret; } int ans; void solve(int idx,int a,int b){ if(a < 0)a = 0; if(b < 0)b = 0; if(a == 3)return; if(b == 3)return; if(idx == n) return; if(s[idx] == 'P'){ ans = (ans + calc(idx+1,a+1,b-1)) % mod; solve(idx+1,a-1,b+1); }else{ solve(idx+1,a+1,b-1); } } int main(){ memset(dp,-1,sizeof(dp)); cin>>n>>mod>>s; calc(0,0,0); solve(0,0,0); cout << (ans + 1)%mod << endl; }
#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...