이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const long long MAX=1e5+1;
long long n;
string s;
long long dp[MAX][4][4][4][4];
long long check(long long a, long long b, long long c)
{
set<long long> st;
if(a!=0)st.insert(a);
if(b!=0)st.insert(b);
if(c!=0)st.insert(c);
return st.size();
}
long long rek(long long i, long long L1,long long L2, long long R1, long long R2)
{
if(i==n)
{
return 0;
}
long long res=0;
if(dp[i][L1][R1][L2][R2]!=-1)return dp[i][L1][L2][R1][R2];
long long 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 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... |