제출 #820167

#제출 시각아이디문제언어결과실행 시간메모리
820167PenguinsAreCuteLinear Garden (IOI08_linear_garden)C++17
95 / 100
51 ms65536 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define mp make_pair #define pb push_back #define LL_MAX LONG_LONG_MAX #define LL_MIN LONG_LONG_MIN #define speed ios_base::sync_with_stdio(false); cin.tie(0) #define stMx(a,b) a = max(a,b) #define stMn(a,b) a = min(a,b) typedef pair<int,int> ii; typedef vector<int> vi; typedef set<int> si; typedef vector<ii> vii; typedef set<ii> sii; #define REP(i, a, b) for(int i = a; i < b; i++) int32_t main() { int N, M, mn=0, mx=0; string S; cin >> N >> M >> S; int dp[N+1][3][3]; REP(k,0,N) REP(i,0,3) REP(j,0,3) dp[k][i][j]=0; if(S[0]=='P') dp[0][1][0]=1; REP(i,1,N) { mn=min((int)0,mn+((S[i-1]=='P')?1:-1)); mx=max((int)0,mx+((S[i-1]=='P')?1:-1)); assert(mn>-3); assert(mx<3); if(S[i]=='P' && mn!=-2) {dp[i][1-mn][max((int)0,mx-1)]++; dp[i][1-mn][max((int)0,mx-1)]%=M;} REP(k,1,3) { dp[i][0][k]+=(dp[i-1][0][k-1]+dp[i-1][1][k-1]); dp[i][1][k]+=dp[i-1][2][k-1]; dp[i][0][k]%=M; dp[i][1][k]%=M; } REP(j,1,3) { dp[i][j][0]+=(dp[i-1][j-1][0]+dp[i-1][j-1][1]); dp[i][j][1]+=dp[i-1][j-1][2]; dp[i][j][0]%=M; dp[i][j][1]%=M; } } int sum=1; REP(i,0,3) REP(j,0,3) sum+=dp[N-1][i][j]; cout<<sum%M; }
#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...