Submission #547295

#TimeUsernameProblemLanguageResultExecution timeMemory
547295krit3379Miners (IOI07_miners)C++17
100 / 100
98 ms616 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 int dp[2][4][4][4][4],ans; int main(){ cin.tie(nullptr)->sync_with_stdio(0); int n,st,c,idx,add,i,j,k,l; string s; cin>>n>>s; for(i=0;i<4;i++)for(j=0;j<4;j++)for(k=0;k<4;k++)for(l=0;l<4;l++)dp[0][i][j][k][l]=dp[1][i][j][k][l]=-1e9; dp[0][0][0][0][0]=0; for(c=0;c<n;c++){ st=c%2; idx=s[c]=='M'?1:s[c]=='B'?2:3; for(i=0;i<4;i++)for(j=0;j<4;j++)for(k=0;k<4;k++)for(l=0;l<4;l++){ add=1; if(i>0&&i!=idx)add++; if(j>0&&j!=idx&&j!=i)add++; dp[1-st][idx][i][k][l]=max(dp[1-st][idx][i][k][l],dp[st][i][j][k][l]+add); add=1; if(k>0&&k!=idx)add++; if(l>0&&l!=idx&&l!=k)add++; dp[1-st][i][j][idx][k]=max(dp[1-st][i][j][idx][k],dp[st][i][j][k][l]+add); ans=max({ans,dp[1-st][idx][i][k][l],dp[1-st][i][j][idx][k]}); } } printf("%d",ans); 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...