제출 #430446

#제출 시각아이디문제언어결과실행 시간메모리
430446arayiLinear Garden (IOI08_linear_garden)C++17
100 / 100
221 ms12984 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; int mod = 1e9 + 7; int n; char A; int ans = 1, dp1[2][2][3], dp[2][4][3], d[N][3]; int main() { fastio; //freopen("input.in", "r", stdin); cin >> n >> mod; dp1[0][0][1] = 1; dp1[0][1][2] = 1; d[0][0] = d[0][1] = 1; for (int i = 1; i <= n; i++) { for(auto i1 : {0, 1}) { for(auto i2 : {1, 2}) dp1[1][i1][i2] = dp1[0][i1][i2-1]; for(auto i2 : {0, 1}) dp1[1][i1][i2] += dp1[0][i1][i2+1], dp1[1][i1][i2] %= mod; } for(auto i1 : {0, 1}) for(auto i2 : {0, 1, 2}) d[i][i1] += dp1[1][i1][i2], d[i][i1] %= mod, dp1[0][i1][i2] = 0; swap(dp1[1], dp1[0]); } dp[0][2][0] = 1; d[0][2] = 1; for (int i = 1; i <= n; i++) { for(auto i1 : {1, 2}) dp[1][i1 + 1][1] += dp[0][i1][1]; for(auto i1 : {2, 3}) dp[1][i1 - 1][1] += dp[0][i1][1], dp[1][i1-1][1]%=mod; for(auto i1 : {0, 1}) dp[1][i1 + 1][2] += dp[0][i1][2]; for(auto i1 : {1, 2}) dp[1][i1 - 1][2] += dp[0][i1][2], dp[1][i1-1][2]%=mod; dp[1][2][0] += dp[0][1][0], dp[1][1][0] += dp[0][2][0]; dp[1][3][1] += dp[0][2][0]; dp[1][3][1] %= mod; dp[1][0][2] += dp[0][1][0]; dp[1][0][2] %= mod; for(auto i1 : {0, 1, 2, 3}) for(auto i2 : {0, 1, 2}) d[i][2] += dp[1][i1][i2], d[i][2]%=mod, dp[0][i1][i2] = 0; swap(dp[0], dp[1]); } int mn = 0, mx = 0; for (int i = 0; i < n; i++) { cin >> A; if(A == '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) ans += d[n-i-1][1]; else if(mx1 - mn1 == 2) ans += d[n-i-1][0]; else ans += d[n-i-1][2]; 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...