Submission #532459

#TimeUsernameProblemLanguageResultExecution timeMemory
532459prvocisloLinear Garden (IOI08_linear_garden)C++17
100 / 100
99 ms5324 KiB
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> typedef long long ll; using namespace std; int m; void upd(int& a, int b) { a = (a + b) % m; } int add(int a, int b) { return (a + b) % m; } int mul(int a, int b) { return (a * 1ll * b) % m; } const int maxn = 1e6 + 5; // dp[kde som][s cim som skoncil][co malo ako posledne dva kusy][nasledujeme ten povodny retazec] int dp[2][3][3][2], v[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n >> m; for (int i = 1; i <= n; i++) { char c; cin >> c; v[i] = (c == 'P'); } dp[0][2][2][1] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) for (int l = 0; l < 2; l++) dp[!(i & 1)][j][k][l] = 0; for (int lst = 0; lst <= 2; lst++) { for (int lst2 = 0; lst2 <= 2; lst2++) { for (int fw = 0; fw < 2; fw++) if (dp[i & 1][lst][lst2][fw]) { for (int now = 0; now < 2 && (!fw || now <= v[i + 1]); now++) { if (now == lst && now == lst2) continue; upd(dp[!(i & 1)][now][(now == lst) ? now : lst2][fw && now == v[i + 1]], dp[i & 1][lst][lst2][fw]); } } } } } int ans = 0; for (int lst = 0; lst <= 2; lst++) { for (int lst2 = 0; lst2 <= 2; lst2++) { for (int fw = 0; fw < 2; fw++) { upd(ans, dp[n & 1][lst][lst2][fw]); } } } cout << ans << "\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...