Submission #396589

#TimeUsernameProblemLanguageResultExecution timeMemory
396589BertedLinear Garden (IOI08_linear_garden)C++14
100 / 100
124 ms2396 KiB
#include <iostream> using namespace std; int N, M, DP[2][3][3][2]; string S; int main() { ios :: sync_with_stdio(0); cin.tie(0); cin >> N >> M >> S; DP[0][0][0][1] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) DP[~i & 1][j][k][0] = DP[~i & 1][j][k][1] = 0; for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j + 1 < 3) { DP[~i & 1][j + 1][max(0, k - 1)][0] = (DP[~i & 1][j + 1][max(0, k - 1)][0] + DP[i & 1][j][k][0]) % M; if (S[i] == 'L') DP[~i & 1][j + 1][max(0, k - 1)][1] = (DP[~i & 1][j + 1][max(0, k - 1)][1] + DP[i & 1][j][k][1]) % M; else DP[~i & 1][j + 1][max(0, k - 1)][0] = (DP[~i & 1][j + 1][max(0, k - 1)][0] + DP[i & 1][j][k][1]) % M; } if (k + 1 < 3) { DP[~i & 1][max(0, j - 1)][k + 1][0] = (DP[~i & 1][max(0, j - 1)][k + 1][0] + DP[i & 1][j][k][0]) % M; if (S[i] == 'P') DP[~i & 1][max(0, j - 1)][k + 1][1] = (DP[~i & 1][max(0, j - 1)][k + 1][1] + DP[i & 1][j][k][1]) % M; } } } } int ret = 0; for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) ret = (ret + DP[N & 1][j][k][0]) % M; } cout << (ret + 1) % M << "\n"; return 0; }
#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...