Submission #995835

#TimeUsernameProblemLanguageResultExecution timeMemory
995835biankLinear Garden (IOI08_linear_garden)C++14
0 / 100
64 ms65536 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6; int memo[MAX_N][5][5][5][2]; int n, m; string g; int dp(int pos, int curr_diff = 2, int min_diff = 2, int max_diff = 2, bool tight = 1) { if (curr_diff < 0 || curr_diff >= 5) return 0; if (max_diff - min_diff >= 3) return 0; if (pos == n) return 1; int &res = memo[pos][curr_diff][min_diff][max_diff][tight]; if (res != -1) return res; res = dp(pos + 1, curr_diff + 1, min_diff, max(max_diff, curr_diff + 1), tight && g[pos] == 'L'); if (!tight || g[pos] == 'P') { res += dp(pos + 1, curr_diff - 1, min(min_diff, curr_diff - 1), max_diff, tight && g[pos] == 'P'); if (res >= m) res -= m; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> g; memset(memo, -1, sizeof memo); cout << dp(0) << '\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...