Submission #1022766

#TimeUsernameProblemLanguageResultExecution timeMemory
1022766nmtsLinear Garden (IOI08_linear_garden)C++17
95 / 100
153 ms65536 KiB
#include <bits/stdc++.h> #define file(name) freopen(name".inp" , " r " , stdin);freopen(name".out" , " w " , stdout) #define faster ios_base :: sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; #define dp(i , mi , ma) dp[i][mi + 2][ma] using namespace std; int n , m; string s; int dp[1000000 - 50][3][3]; void solve() { cin >> n >> m >> s; for (int mi = -2; mi <= 0; ++mi) for (int ma = 0; ma <= 2; ++ma) dp(n + 1, mi, ma) = 1; for (int i = n; i >= 1; --i) { for (int mi = -2; mi <= 0; ++mi) { for (int ma = 0; ma <= 2; ++ma) { if (mi > -2) dp(i, mi, ma) += dp(i + 1, mi - 1, max(0, ma - 1)); if (ma < 2) dp(i, mi, ma) += dp(i + 1, min(0, mi + 1), ma + 1); dp(i, mi, ma) %= m; } } } s = " " + s; int ans = 1; for (int i = 1 , mi = 0 , ma = 0 ; i <= n ; ++i) if (s[i] == 'L') { mi--; ma = max(0 , ma - 1); } else { if (mi > -2) ans = (ans + dp(i + 1 , mi - 1 , max(mi - 1 , 0))) % m; ma++; mi = min(0 , mi + 1); } cout << ans << endl; } int32_t main() { faster; solve(); 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...