제출 #132937

#제출 시각아이디문제언어결과실행 시간메모리
132937Mahmoud_AdelLinear Garden (IOI08_linear_garden)C++14
0 / 100
72 ms65540 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[N][2][3][3]; string s; ll sol(int i, int bit, int l, int p) { 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; } int main() { memset(dp, -1, sizeof dp); cin >> n >> mod >> s; cout << sol(0, 0, 0, 0) << 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...