이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,a,b) for(int i=a; i<(b); i++)
#define all(x) x.begin(),x.end()
using ll=long long;
const int INF=INT_MAX>>1;
int main(){
int N;
cin>>N;
string S;
cin>>S;
rep(i,N){
if(S[i]=='M'){
S[i]='a';
}
if(S[i]=='F'){
S[i]='b';
}
if(S[i]=='B'){
S[i]='c';
}
}
vector<int> dp(1600,-INF);
dp[0]=0;
array<string,40> ser;
ser[0]="ddd";
int cnt=1;
rep(i,3){
ser[cnt]="ddd";
ser[cnt][2]='a'+i;
cnt++;
rep(j,3){
ser[cnt]="ddd";
ser[cnt][2]='a'+i;
ser[cnt][1]='a'+j;
cnt++;
rep(k,3){
ser[cnt]="ddd";
ser[cnt][2]='a'+i;
ser[cnt][1]='a'+j;
ser[cnt][0]='a'+k;
cnt++;
}
}
}
array<int,64> num;
array<int,64> score;
array<int,40> fix;
rep(i,40){
num[(ser[i][0]-'a')+(ser[i][1]-'a')*4+(ser[i][2]-'a')*16]=i;
fix[i]=(ser[i][0]-'a')+(ser[i][1]-'a')*4+(ser[i][2]-'a')*16;
int cnt[4];
cnt[0]=0;
cnt[1]=0;
cnt[2]=0;
cnt[(ser[i][0]-'a')]++;
cnt[(ser[i][1]-'a')]++;
cnt[(ser[i][2]-'a')]++;
score[(ser[i][0]-'a')+(ser[i][1]-'a')*4+(ser[i][2]-'a')*16]=0;
if(cnt[0]!=0){
score[(ser[i][0]-'a')+(ser[i][1]-'a')*4+(ser[i][2]-'a')*16]++;
}
if(cnt[1]!=0){
score[(ser[i][0]-'a')+(ser[i][1]-'a')*4+(ser[i][2]-'a')*16]++;
}
if(cnt[2]!=0){
score[(ser[i][0]-'a')+(ser[i][1]-'a')*4+(ser[i][2]-'a')*16]++;
}
}
rep(i,N){
vector<int> ndp(1600,-INF);
rep(j,40){
rep(k,40){
if(dp[j*40+k]<=-INF)continue;
int nj=fix[j]/4+(S[i]-'a')*16;
int nk=fix[k]/4+(S[i]-'a')*16;
ndp[num[nj]*40+k]=max(ndp[num[nj]*40+k],dp[j*40+k]+score[nj]);
ndp[j*40+num[nk]]=max(ndp[j*40+num[nk]],dp[j*40+k]+score[nk]);
}
}
dp=move(ndp);
}
int ans=0;
rep(i,1600){
ans=max(ans,dp[i]);
}
cout<<ans<<"\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... |