Submission #235594

#TimeUsernameProblemLanguageResultExecution timeMemory
235594Haunted_CppLinear Garden (IOI08_linear_garden)C++17
100 / 100
530 ms1556 KiB
/** * author: Duarte Nobrega * created: 28.05.2020 **/ #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int dp [2][5][5][3], n, MOD; string w; void add (int &a, int b) { a += b; if (a >= MOD) a -= MOD; } int calc (int estado, char cur, char is) { if (estado > 0) return estado; if (cur < is) return 1; if (cur > is) return 2; return 0; } int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> MOD >> w; memset (dp, 0, sizeof(dp)); dp[0][2][2][0] = 1; for (int i = 0; i < n; i++) { for (int maior = 0; maior < 5; maior++) { for (int menor = 0; menor < 5; menor++) { for (int estado = 0; estado < 3; estado++) { // Place L if (maior - 1 >= 0 && min (menor - 1, 1) >= 0) { add (dp[(i + 1) & 1][maior - 1][min (menor - 1, 1)][calc (estado, 'L', w[i])], dp[i & 1][maior][menor][estado]); } // Place P if (menor + 1 < 5 && max (maior + 1, 3) < 5) { add(dp[(i + 1) & 1][max (maior + 1, 3)][menor + 1][calc (estado, 'P', w[i])], dp[i & 1][maior][menor][estado]); } } } } for (int maior = 0; maior < 5; maior++) { for (int menor = 0; menor < 5; menor++) { for (int estado = 0; estado < 3; estado++) { dp[i & 1][maior][menor][estado] = 0; } } } } int res = 0; for (int maior = 0; maior < 5; maior++) { for (int menor = 0; menor < 5; menor++) { add (res, dp[n & 1][maior][menor][1]); } } add(res, 1); cout << res << '\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...