Submission #995838

#TimeUsernameProblemLanguageResultExecution timeMemory
995838biankLinear Garden (IOI08_linear_garden)C++14
100 / 100
899 ms2552 KiB
#include <bits/stdc++.h> using namespace std; int prev_dp[5][5][3][2]; int curr_dp[5][5][3][2]; int n, m; string g; int getVal(int curr_diff, int min_diff, int max_diff, bool tight) { if (curr_diff < 0 || curr_diff >= 5) return 0; if (max_diff - min_diff >= 3) return 0; return prev_dp[curr_diff][min_diff][max_diff - min_diff][tight]; } void compute(int pos, int curr_diff, int min_diff, int max_diff, bool tight) { int &res = curr_dp[curr_diff][min_diff][max_diff - min_diff][tight]; res = getVal(curr_diff + 1, min_diff, max(max_diff, curr_diff + 1), tight && g[pos] == 'L'); if (!tight || g[pos] == 'P') { res += getVal(curr_diff - 1, min(min_diff, curr_diff - 1), max_diff, tight && g[pos] == 'P'); if (res >= m) res -= m; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> g; for (int curr_diff = 0; curr_diff < 5; curr_diff++) { for (int min_diff = 0; min_diff < 5; min_diff++) { for (int max_diff = min_diff; max_diff - min_diff < 3; max_diff++) { for (bool tight : {false, true}) { prev_dp[curr_diff][min_diff][max_diff - min_diff][tight] = 1; } } } } for (int pos = n - 1; pos >= 0; pos--) { for (int curr_diff = 0; curr_diff < 5; curr_diff++) { for (int min_diff = 0; min_diff < 5; min_diff++) { for (int max_diff = min_diff; max_diff - min_diff < 3; max_diff++) { for (bool tight : {false, true}) { compute(pos, curr_diff, min_diff, max_diff, tight); } } } } for (int curr_diff = 0; curr_diff < 5; curr_diff++) { for (int min_diff = 0; min_diff < 5; min_diff++) { for (int max_diff = min_diff; max_diff - min_diff < 3; max_diff++) { for (bool tight : {false, true}) { prev_dp[curr_diff][min_diff][max_diff - min_diff][tight] = curr_dp[curr_diff][min_diff][max_diff - min_diff][tight]; curr_dp[curr_diff][min_diff][max_diff - min_diff][tight] = 0; } } } } } cout << prev_dp[2][2][0][1] << '\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...