제출 #262877

#제출 시각아이디문제언어결과실행 시간메모리
262877ElyesChaabouniLinear Garden (IOI08_linear_garden)C++14
85 / 100
99 ms65540 KiB
/*#pragma GCC optimize("O3")*/ #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> #define eps 1e-9 #define MOD1 998244353 #define MOD2 1000000007 #define INV_10 299473306 #define INF 1000000000 #define PI 3.14159265358979323846 using namespace std; int dp[1000001][9][2]; bitset<1000001>a; int n, m, pp, ll; int solve(int idx, int d, bool b) { if(idx==n) return 1; if(dp[idx][d][b]!=-1) return dp[idx][d][b]; dp[idx][d][b]=0; if(a.test(idx)) { if(d/3 < 2) { pp=d/3; ll=d%3; pp++; ll--; ll=max(ll, 0); dp[idx][d][b]+=solve(idx+1, pp*3+ll, b); dp[idx][d][b]%=m; } if(d%3 < 2) { pp=d/3; ll=d%3; pp--; ll++; pp=max(0, pp); dp[idx][d][b]+=solve(idx+1, pp*3+ll, 1); dp[idx][d][b]%=m; } } else { if(d%3 < 2) { pp=d/3; ll=d%3; pp--; ll++; pp=max(0, pp); dp[idx][d][b]+=solve(idx+1, pp*3+ll, b); dp[idx][d][b]%=m; } if(d/3 < 2 && b) { pp=d/3; ll=d%3; pp++; ll--; ll=max(ll, 0); dp[idx][d][b]+=solve(idx+1, pp*3+ll, b); dp[idx][d][b]%=m; } } return dp[idx][d][b]; } int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m; char c; for(int i = 0; i < n; i++) { cin >> c; if(c=='P') a[i]=1; } for(int i = 0; i <= n; i++) for(int k = 0; k < 9; k++) for(int l = 0; l < 2; l++) dp[i][k][l]=-1; cout << solve(0, 0, 0) << '\n'; } //size
#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...