Submission #584114

#TimeUsernameProblemLanguageResultExecution timeMemory
584114AtinaRMiners (IOI07_miners)C++14
52 / 100
1595 ms111692 KiB
#include <bits/stdc++.h> using namespace std; const int MAX=1e5+10; int n; string s; int dp[MAX][4][4][4][4]; int check(int a, int b, int c) { set<int> st; if(a!=0)st.insert(a); if(b!=0)st.insert(b); if(c!=0)st.insert(c); return st.size(); } int rek(int i, int L1,int L2, int R1, int R2) { if(i==n) { return 0; } int res=0; if(dp[i][L1][R1][L2][R2]!=-1)return dp[i][L1][L2][R1][R2]; int tmp; if(s[i]=='M') { tmp=1; } else if(s[i]=='B') { tmp=2; } else { tmp=3; } res=rek(i+1,tmp,L1, R1, R2)+check(tmp,L1,L2); res=max(res,rek(i+1,L1,L2,tmp,R1)+check(tmp,R1,R2)); return dp[i][L1][L2][R1][R2]=res; } int main() { cin>>n; cin>>s; memset(dp,-1,sizeof(dp)); cout<<rek(0,0,0,0,0)<<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...