이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 10000000
#define MAXN 100005
typedef pair<int, int> pii;
ll int DP[MAXN][4][4][4][4];
bitset<4>bi;
int main(){
ll int n,i,k,a,b,c,d,cur,ans=0;
cin>>n;
string s;
cin>>s;
memset(DP,(ll int)-1,sizeof(DP));
DP[0][0][0][0][0]=0;
for(i=1;i<=n;i++){
if(s[i]=='M'){
k=1;
}else if(s[i]=='F'){
k=2;
}else{
k=3;
}
for(a=0;a<=3;a++){
for(b=0;b<=3;b++){
for(c=0;c<=3;c++){
for(d=0;d<=3;d++){
cur = DP[i-1][a][b][c][d];
if(cur==-1)continue;
if( (b==0&&a!=0) || (d==0&&c!=0) )continue;
//vai para left
bi.reset();
bi[a]=1; bi[b]=1; bi[k]=1; bi[0]=0;
DP[i][b][k][c][d] = max(DP[i][b][k][c][d],cur+(int)bi.count());
//vai para right
bi.reset();
bi[c]=1; bi[d]=1; bi[k]=1; bi[0]=0;
DP[i][a][b][d][k] = max(DP[i][a][b][d][k],cur+(int)bi.count());
} } } }
}
for(a=0;a<=3;a++){
for(b=0;b<=3;b++){
for(c=0;c<=3;c++){
for(d=0;d<=3;d++){
ans=max(ans,DP[n][a][b][c][d]);
//cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<DP[n-1][a][b][c][d]<<" "<<DP[n][a][b][c][d]<<"\n";
} } } }
cout<<ans<<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... |