제출 #581584

#제출 시각아이디문제언어결과실행 시간메모리
581584HeyYouNotYouYouMiners (IOI07_miners)C++14
100 / 100
839 ms210280 KiB
#include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; const int N = 100001,INF=1e12; int n; string s; int dp[N][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 solve(int i,int preva1,int prevb1,int preva2,int prevb2) { //cout<<i<<" "<<preva1<<" "<<preva2<<" "<<prevb1<<" "<<prevb2<<endl; if(i==n) return 0; int ans=0; if(dp[i][preva1][prevb1][preva2][prevb2]!=-1) return dp[i][preva1][prevb1][preva2][prevb2]; int x; if(s[i]=='M') x=1; else if(s[i]=='B') x=2; else x=3; ans=solve(i+1,preva1,prevb1,prevb2,x)+check(preva2,prevb2,x); ans=max(ans,solve(i+1,prevb1,x,preva2,prevb2)+check(preva1,prevb1,x)); return dp[i][preva1][prevb1][preva2][prevb2]=ans; } int32_t main() { //freopen("abc.in", "r", stdin); cin >> n ; cin>>s; memset(dp,-1,sizeof dp); cout<<solve(0,0,0,0,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...