제출 #532455

#제출 시각아이디문제언어결과실행 시간메모리
532455prvocisloLinear Garden (IOI08_linear_garden)C++17
95 / 100
97 ms65540 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[maxn][3][3][2]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n >> m; string s; cin >> s; vector<int> v(n + 1); for (int i = 1; i <= n; i++) v[i] = (s[i - 1] == 'P'); dp[0][2][2][1] = 1; for (int i = 0; i < n; i++) { for (int lst = 0; lst <= 2; lst++) { for (int lst2 = 0; lst2 <= 2; lst2++) { for (int fw = 0; fw < 2; fw++) if (dp[i][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][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][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...