제출 #132942

#제출 시각아이디문제언어결과실행 시간메모리
132942Mahmoud_AdelLinear Garden (IOI08_linear_garden)C++14
100 / 100
268 ms3376 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second typedef long long ll; const int N = 1e6+5; int n, mod; ll dp[2][2][3][3]; string s; ll sol(int i, int bit, int l, int p) { return dp[i%2][bit][l][p]; } ll solve() { //~ if(i == n) return 1; //~ ll &ret = dp[i][bit][l][p]; //~ if(ret != -1) return ret; //~ ret = 0; //~ if(bit) //~ { //~ if(l < 2) ret += sol(i+1, bit, l+1, max(0, p-1)); //~ if(p < 2) ret += sol(i+1, bit, max(l-1, 0), p+1), ret %= mod; //~ } //~ else //~ { //~ if(s[i] == 'L') ret += sol(i+1, bit, l+1, max(p-1, 0)); //~ else //~ { //~ if(l < 2) ret += sol(i+1, 1, l+1, max(p-1, 0)); //~ ret += sol(i+1, 0, max(0, l-1), p+1), ret %= mod; //~ } //~ } //~ return ret; for(int i=0; i<2; i++) for(int j=0; j<3; j++) for(int k=0; k<3; k++) dp[n%2][i][j][k] = 1; for(int i=n-1; i>=0; i--) { for(int bit=0; bit<2; bit++) { for(int l=0; l<3; l++) { for(int p=0; p<3; p++) { ll &ret = dp[i%2][bit][l][p]; ret = 0; if(bit) { if(l < 2) ret += sol(i+1, bit, l+1, max(0, p-1)); if(p < 2) ret += sol(i+1, bit, max(l-1, 0), p+1), ret %= mod; } else { if(s[i] == 'L') ret += sol(i+1, bit, l+1, max(p-1, 0)); else { if(l < 2) ret += sol(i+1, 1, l+1, max(p-1, 0)); ret += sol(i+1, 0, max(0, l-1), p+1), ret %= mod; } } } } } } return dp[0][0][0][0]; } int main() { memset(dp, -1, sizeof dp); cin >> n >> mod >> s; cout << solve() << 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...