제출 #1046127

#제출 시각아이디문제언어결과실행 시간메모리
1046127ZicrusLinear Garden (IOI08_linear_garden)C++17
100 / 100
51 ms41400 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int G[3][3] = {{0, 1, 2}, {3, 4, -1}, {5, -1, -1}}; int main() { int n, m; cin >> n >> m; string s; cin >> s; vector<int*> dp(n+1); for (int i = 0; i <= n; i++) { dp[i] = new int[6]; } dp[n][G[0][0]] = dp[n][G[1][1]] = 1; dp[n][G[1][0]] = dp[n][G[0][1]] = 1; dp[n][G[2][0]] = dp[n][G[0][2]] = 1; for (int i = n-1; i >= 0; i--) { dp[i][G[0][0]] = (dp[i+1][G[1][0]] + dp[i+1][G[0][1]]) % m; dp[i][G[1][1]] = (dp[i+1][G[2][0]] + dp[i+1][G[0][2]]) % m; dp[i][G[1][0]] = (dp[i+1][G[2][0]] + dp[i+1][G[0][1]]) % m; dp[i][G[0][1]] = (dp[i+1][G[1][0]] + dp[i+1][G[0][2]]) % m; dp[i][G[2][0]] = dp[i][G[0][2]] = dp[i+1][G[1][1]] % m; } int res = 1; int low = 0, high = 0; for (int i = 0; i < n; i++) { if (s[i] == 'P') { if (low > -2) res += dp[i+1][G[-(low-1)][max(0, high-1)]]; res %= m; low = min(0, low+1); high++; } else { low--; high = max(0, high-1); } } cout << res; }
#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...