제출 #995839

#제출 시각아이디문제언어결과실행 시간메모리
995839biankLinear Garden (IOI08_linear_garden)C++14
100 / 100
320 ms1528 KiB
#include <bits/stdc++.h> using namespace std; int prevDP[5][3][3][2], currDP[5][3][3][2]; inline int getVal(int curr, int mini, int maxi, bool tight) { if (curr < 0 || curr >= 5) return 0; if (maxi - mini >= 3) return 0; return prevDP[curr][curr - mini][maxi - mini][tight]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; string g; cin >> n >> m >> g; #define FORALLSTATES for (int curr = 0; curr < 5; curr++) \ for (int mini = curr; curr - mini < 3; mini--) \ for (int maxi = curr; maxi - mini < 3; maxi++) \ for (bool tight : {false, true}) FORALLSTATES { prevDP[curr][curr - mini][maxi - mini][tight] = 1; } for (int pos = n - 1; pos >= 0; pos--) { FORALLSTATES { int &res = currDP[curr][curr - mini][maxi - mini][tight]; res = getVal(curr + 1, mini, max(maxi, curr + 1), tight && g[pos] == 'L'); if (!tight || g[pos] == 'P') { res += getVal(curr - 1, min(mini, curr - 1), maxi, tight && g[pos] == 'P'); if (res >= m) res -= m; } } FORALLSTATES { prevDP[curr][curr - mini][maxi - mini][tight] = currDP[curr][curr - mini][maxi - mini][tight]; currDP[curr][curr - mini][maxi - mini][tight] = 0; } } cout << prevDP[2][0][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...