Submission #160198

#TimeUsernameProblemLanguageResultExecution timeMemory
160198johuthaLinear Garden (IOI08_linear_garden)C++14
100 / 100
221 ms57348 KiB
#include <iostream> #include <vector> #define int int64_t using namespace std; signed main() { int n, m; string st; cin >> n >> m >> st; vector<vector<int>> nrstrings(n + 1, vector<int>(3, 0)); nrstrings[0][0] = 1; nrstrings[1][0] = 1; for (int i = 2; i <= n; i++) { nrstrings[i][1] += nrstrings[i - 1][0]; nrstrings[i][1] += nrstrings[i - 1][2]; if (i > 1) { nrstrings[i][0] += nrstrings[i - 2][0]; nrstrings[i][1] += nrstrings[i - 2][1]; nrstrings[i][2] += nrstrings[i - 2][2]; } if (i > 2) { nrstrings[i][2] += nrstrings[i - 3][0]; nrstrings[i][2] += nrstrings[i - 3][1]; } nrstrings[i][0] %= m; nrstrings[i][1] %= m; nrstrings[i][2] %= m; } int res = 1; char bef = '0'; char doub = '1'; for (int i = 0; i < n; i++) { if (st[i] == 'P' && bef != doub) { res += nrstrings[n - i][0]; if (doub != 'P' || bef == 'L') res += nrstrings[n - i][2]; if (doub != 'L' && bef != 'L') res += nrstrings[n - i][1]; } if (st[i] == bef) { doub = st[i]; } bef = st[i]; res %= m; } cout << res << "\n"; }
#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...