Submission #535857

#TimeUsernameProblemLanguageResultExecution timeMemory
535857cig32Miners (IOI07_miners)C++17
100 / 100
198 ms109032 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" typedef long long int ll; const int N=1e5+7; string s; int n; int c(int a,int b,int c){ int sol = 0; if (a == 1 || b == 1 || c == 1) sol++; if (a == 2 || b == 2 || c == 2) sol++; if (a == 3 || b == 3 || c == 3) sol++; return sol; } int a[N]; int dp[N][4][4][4][4]; int solve(int idx,int prea1,int prea2,int preb1,int preb2){ if(idx==n) { return 0; } int &ans=dp[idx][prea1][prea2][preb1][preb2]; if(ans!=-1) return ans; int choice1=solve(idx+1,a[idx],prea1,preb1,preb2)+c(a[idx],prea1,prea2); int choice2=solve(idx+1,prea1,prea2,a[idx],preb1)+c(a[idx],preb1,preb2); return ans=max(choice1,choice2); } int main() { ios_base:: sync_with_stdio(false); cin.tie(0); cin>>n; cin>>s; for(int i=0; i<n; i++) { if(s[i]=='B') { a[i]=3; } else if(s[i]=='M') { a[i]=1; } else{ a[i]=2; } } memset(dp,-1,sizeof dp); int ans=solve(0,0,0,0,0); cout<<ans<<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...