이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
typedef pair<int,int> pii;
int N;
char c;
int DP[4][4][4][4][100005];
int T[100005];
int C(pii a, int b){
int A[]={0,0,0,0};
A[a.first]=1;
A[a.second]=1;
A[b]=1;
return A[1]+A[2]+A[3];
}
int F(pii a, pii b, int k){
if(k==N) return 0;
if(!DP[a.first][a.second][b.first][b.second][k])
DP[a.first][a.second][b.first][b.second][k]=
max(
F({a.second,T[k]},b,k+1)+C(a,T[k]),
F(a,{b.second,T[k]},k+1)+C(b,T[k])
);
return DP[a.first][a.second][b.first][b.second][k];
}
int main(){
cin>>N;
for(int i=0;i<N;i++){
cin>>c;
if(c=='M')
T[i]=1;
else if(c=='F')
T[i]=2;
else
T[i]=3;
}
cout<<F({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... |