이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
int n,ar[2][4][4][4][4]={},mx=1;string s;
int ts(char a)
{
if (a=='M') {return 1;}
else if (a=='B') {return 2;}
else {return 3;}
}
int hm(int a,int b,int c)
{
bool mp[4]={};int to=0;
if (a!=0&&!mp[a]) {mp[a]=true;to++;}
if (b!=0&&!mp[b]) {mp[b]=true;to++;}
if (c!=0&&!mp[c]) {mp[c]=true;to++;}
return to;
}
int main()
{
/*
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif*/
cin>>n>>s;
ar[1][0][0][0][ts(s[0])] = 1;
ar[1][0][ts(s[0])][0][0] = 1;
for (int a=2;a<=n;a++)
{
for (int b=0;b<4;b++)
{
for (int c=0;c<4;c++)
{
for (int d=0;d<4;d++)
{
for (int e=0;e<4;e++)
{
if (ar[(a-1)%2][b][c][d][e]>0)
{
ar[a%2][c][ts(s[a-1])][d][e] = max(ar[a%2][c][ts(s[a-1])][d][e],ar[(a-1)%2][b][c][d][e]+hm(b,c,ts(s[a-1])));
ar[a%2][b][c][e][ts(s[a-1])] = max(ar[a%2][b][c][e][ts(s[a-1])],ar[(a-1)%2][b][c][d][e]+hm(d,e,ts(s[a-1])));
mx=max(mx,ar[a%2][c][ts(s[a-1])][d][e]);
mx=max(mx,ar[a%2][b][c][e][ts(s[a-1])]);
}
}
}
}
}
}
cout<<mx<<"\n";
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... |