제출 #1046116

#제출 시각아이디문제언어결과실행 시간메모리
1046116ZicrusLinear Garden (IOI08_linear_garden)C++17
85 / 100
61 ms65536 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; 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*[3]; dp[i][0] = new int[3]; dp[i][1] = new int[3]; dp[i][2] = new int[3]; } dp[n][0][0] = dp[n][1][1] = 1; dp[n][1][0] = dp[n][0][1] = 1; dp[n][2][0] = dp[n][0][2] = 1; for (int i = n-1; i >= 0; i--) { dp[i][0][0] = (dp[i+1][1][0] + dp[i+1][0][1]) % m; dp[i][1][1] = (dp[i+1][2][0] + dp[i+1][0][2]) % m; dp[i][1][0] = (dp[i+1][2][0] + dp[i+1][0][1]) % m; dp[i][0][1] = (dp[i+1][1][0] + dp[i+1][0][2]) % m; dp[i][2][0] = dp[i][0][2] = dp[i+1][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][-(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...