이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MAX 110000
int array[MAX];
bool existe[MAX][3][3][3][3][3][3];
int tab[MAX][3][3][3][3][3][3];
typedef std::pair<int,int> prev;
int N;
int dp(int pos,int v1,int v2,int v3,int v4,int v5,int v6){
if(pos==N)return 0;
if(existe[pos][v1][v2][v3][v4][v5][v6])return tab[pos][v1][v2][v3][v4][v5][v6];
existe[pos][v1][v2][v3][v4][v5][v6]=true;
int best = 0;
///Mina 1
{
bool diferentes[3]={};
if(v3)diferentes[v1]=true;
if(v3>1)diferentes[v2]=true;
diferentes[array[pos]]=true;
int bonus = diferentes[0] + diferentes[1] + diferentes[2];
best = std::max(best,bonus+
dp(pos+1,array[pos],v1,std::min(v3+1,2),v4,v5,v6));
}
{
bool diferentes[3]={};
if(v6)diferentes[v4]=true;
if(v6>1)diferentes[v5]=true;
diferentes[array[pos]]=true;
int bonus = diferentes[0] + diferentes[1] + diferentes[2];
best = std::max(best,bonus+
dp(pos+1,v1,v2,v3,array[pos],v4,std::min(v6+1,2)));
}
return tab[pos][v1][v2][v3][v4][v5][v6]=best;
}
int main()
{
std::cin>>N;
std::string s;
std::cin>>s;
for(int i=0;i!=N;++i){
if(s[i]=='B')array[i]=0;
else if(s[i]=='F')array[i]=1;
else array[i]=2;
}
std::cout << dp(0,0,0,0,0,0,0) << "\n";
}
# | 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... |