이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |