Submission #782518

#TimeUsernameProblemLanguageResultExecution timeMemory
782518phoebeLinear Garden (IOI08_linear_garden)C++17
85 / 100
59 ms65536 KiB
#include <bits/stdc++.h> using namespace std; // #define int long long #define ll long long #define pii pair<int, int> #define F first #define S second #define PB push_back #define ALL(x) x.begin(), x.end() #define FOR(i, n) for (int i = 0; i < n; i++) #define NYOOM ios::sync_with_stdio(0); cin.tie(0); #define endl '\n' const int INF = 1e9 + 7; const ll LLINF = 1ll<<60; const int maxn = 1e6 + 10; int n, m, dp[3][3][maxn]; string s; int cnt(int mn, int mx, int rem){ // mn = min(l - p), mx = max(l - p) if (mn <= -3 || mx >= 3) return 0; if (rem <= 0) return 1; if (dp[-mn][mx][rem] != -1) return dp[-mn][mx][rem]; int go_l = cnt(min(mn + 1, 0), mx + 1, rem - 1); int go_p = cnt(mn - 1, max(0, mx - 1), rem - 1); dp[-mn][mx][rem] = (go_l + go_p) % m; return dp[-mn][mx][rem]; } signed main(){ NYOOM; fill(&dp[0][0][0], &dp[0][0][0] + 3 * 3 * maxn, -1); cin >> n >> m; cin >> s; int re = 1, mn = 0, mx = 0; FOR(i, n){ if (s[i] == 'L'){ mn = min(0, mn + 1), mx = mx + 1; continue; } // cur is p int rem = n - i - 1; int go_l = cnt(min(mn + 1, 0), mx + 1, rem); mn = mn - 1, mx = max(0, mx - 1); re = (re + go_l) % m; } cout << re; }
#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...