Submission #721441

#TimeUsernameProblemLanguageResultExecution timeMemory
721441Yell0Miners (IOI07_miners)C++17
74 / 100
171 ms1016 KiB
#include <bits/stdc++.h> using namespace std; const int MN=1e5+2; int N,dp[2][4][4][4][4],a[MN]; string s; inline int calc(char x,char y,char z) { return (x==1||y==1||z==1)+(x==2||y==2||z==2)+(x==3||y==3||z==3); } int main() { ios::sync_with_stdio(0);cin.tie(0); cin>>N>>s; for(int i=0;i<N;++i) { if(s[i]=='B') a[i+1]=1; if(s[i]=='F') a[i+1]=2; if(s[i]=='M') a[i+1]=3; } for(int i=0;i<2;++i) for(int j=0;j<4;++j) for(int k=0;k<4;++k) for(int l=0;l<4;++l) for(int m=0;m<4;++m) dp[i][j][k][l][m]=INT_MIN; dp[0][0][0][0][0]=0; int ans=0; for(int i=1;i<=N;++i) for(int j=0;j<4;++j) for(int k=0;k<4;++k) for(int l=0;l<4;++l) for(int m=0;m<4;++m) { dp[i&1][k][a[i]][l][m]=max(dp[i&1][k][a[i]][l][m],dp[(i-1)&1][j][k][l][m]+calc(a[i],j,k)); dp[i&1][j][k][m][a[i]]=max(dp[i&1][j][k][m][a[i]],dp[(i-1)&1][j][k][l][m]+calc(a[i],l,m)); ans=max({ans,dp[i&1][j][a[i]][l][m],dp[i&1][j][k][l][a[i]]}); } cout<<ans<<'\n'; 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...