Submission #480589

#TimeUsernameProblemLanguageResultExecution timeMemory
480589tht2005Linear Garden (IOI08_linear_garden)C++14
100 / 100
51 ms2408 KiB
/** * Magician: tht2005 * Spawned: 2021.10.17 14:12:11 **/ #include <bits/stdc++.h> using namespace std; int n, md, res, dp[3][3][2], aux[3][3][2]; string s; void add(int& a, int b) { if((a += b) >= md) a -= md; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> md >> s; dp[0][0][0] = 1; for(int i = 0; i < n; ++i) { for(int j = 0; j < 3; ++j) { for(int k = 0; k < 3; ++k) { for(int l = 0; l < 2; ++l) { aux[j][k][l] = dp[j][k][l]; dp[j][k][l] = 0; } } } for(int j = 0; j < 3; ++j) { for(int k = 0; k < 3; ++k) { for(int l = 0; l < 2; ++l) { int ft = aux[j][k][l]; if(ft > 0) { if(j < 2) add(dp[j + 1][max(0, k - 1)][(int)(l || s[i] == 'P')], ft); if((l || s[i] == 'P') && k < 2) add(dp[max(0, j - 1)][k + 1][l], ft); } } } } } res = 0; for(int i = 0; i < 3; ++i) { for(int j = 0; j < 3; ++j) { for(int k = 0; k < 2; ++k) { add(res, dp[i][j][k]); } } } cout << res; 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...