제출 #396588

#제출 시각아이디문제언어결과실행 시간메모리
396588BertedLinear Garden (IOI08_linear_garden)C++14
95 / 100
151 ms65540 KiB
#include <iostream> using namespace std; int N, M, DP[1000001][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++) { 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][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][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][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][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][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][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...