Submission #655330

#TimeUsernameProblemLanguageResultExecution timeMemory
655330NakeebMiners (IOI07_miners)C++17
100 / 100
899 ms141500 KiB
#include<bits/stdc++.h> using namespace std; int n; string s; map<char,int>mp; int dp[100005][4][4][4][4]; int solve(int i, string a, string b) { int in1=mp[a[0]],in2=mp[a[1]],in3=mp[b[0]],in4=mp[b[1]]; if(i==n) return 0; if(~dp[i][in1][in2][in3][in4]) return dp[i][in1][in2][in3][in4]; string c=""; c+=a[0],c+=a[1],c+=s[i]; string d=""; d+=b[0],d+=b[1],d+=s[i]; int m=0,f=0,q=0; for(int i=0;i<3;i++) { if(c[i]=='M') m++; else if(c[i]=='F') f++; else if(c[i]=='B') q++; } string cc={c[1],c[2]}; int c1=solve(i+1,cc,b)+min(m,1)+min(f,1)+min(q,1); m=0,f=0,q=0; for(int i=0;i<3;i++) { if(d[i]=='M') m++; else if(d[i]=='F') f++; else if(d[i]=='B') q++; } string dd={d[1],d[2]}; int c2=solve(i+1,a,dd)+min(m,1)+min(f,1)+min(q,1); return dp[i][in1][in2][in3][in4]=max(c1,c2); } int main() { memset(dp,-1 ,sizeof(dp)); mp['.']=0; mp['M']=1; mp['F']=2; mp['B']=3; cin>>n; cin>>s; cout<<solve(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...