Submission #429816

#TimeUsernameProblemLanguageResultExecution timeMemory
429816arayiLinear Garden (IOI08_linear_garden)C++17
85 / 100
72 ms65540 KiB
//Arayi #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <queue> #include <stack> #include <algorithm> #include <math.h> #include <vector> #include <cstring> #include <ctime> #include <set> #include <bitset> #include <map> #include <unordered_map> #include <unordered_set> #include <iomanip> #include <ctime> #include <climits> #include <cassert> #include <chrono> #include <random> #include <complex> #define fr first #define sc second #define MP make_pair #define ad push_back #define PB push_back #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define lli long long int #define y1 arayikhalatyan #define j1 jigglypuff #define ld long double #define itn int #define pir pair<int, int> #define all(x) (x).begin(), (x).end() #define str string #define enl endl #define en endl #define cd complex<long double> #define vcd vector<cd> #define vii vector<int> #define vlli vector<lli> using namespace std; const int N = 1e6 + 30; lli mod = 1e9 + 7; int n; str s; lli ans = 1, dp1[2][N][3], dp[N][4][3]; int main() { fastio; //freopen("input.in", "r", stdin); cin >> n >> mod >> s; dp1[0][0][1] = 1; dp1[1][0][2] = 1; for (int i = 1; i <= n; i++) { for(auto i1 : {0, 1}) { for(auto i2 : {1, 2}) dp1[i1][i][i2] = dp1[i1][i-1][i2-1]; for(auto i2 : {0, 1}) dp1[i1][i][i2] += dp1[i1][i-1][i2+1], dp1[i1][i][i2] %= mod; } } dp[0][2][0] = 1; for (int i = 1; i <= n; i++) { for(auto i1 : {1, 2}) dp[i][i1 + 1][1] += dp[i-1][i1][1]; for(auto i1 : {2, 3}) dp[i][i1 - 1][1] += dp[i-1][i1][1], dp[i][i1-1][1]%=mod; for(auto i1 : {0, 1}) dp[i][i1 + 1][2] += dp[i-1][i1][2]; for(auto i1 : {1, 2}) dp[i][i1 - 1][2] += dp[i-1][i1][2], dp[i][i1-1][2]%=mod; dp[i][2][0] += dp[i-1][1][0], dp[i][1][0] += dp[i-1][2][0]; dp[i][3][1] += dp[i-1][2][0]; dp[i][3][1] %= mod; dp[i][0][2] += dp[i-1][1][0]; dp[i][0][2] %= mod; } int mn = 0, mx = 0; for (int i = 0; i < n; i++) { if(s[i] == 'L') { mn = min(0, mn + 1); mx++; } else { int mn1 = min(0, mn + 1); int mx1 = mx + 1; if(mx1 - mn1 <= 2) { if(mx1 == 2) for(auto i1 : {0,1,2}) ans += dp1[1][n-i-1][i1]; else if(mx1 - mn1 == 2) for(auto i1 : {0,1,2}) ans += dp1[0][n-i-1][i1]; else for(auto i1 : {0,1,2,3}) {for(auto i2 : {0,1,2}) ans += dp[n-i-1][i1][i2];} ans %= mod; } mn--; mx=max(0, mx-1); } //cout << ans << " "; } cout<<ans<<endl; 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...