이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int x,dp[1000005][16][16];
map<char,int>mp;
string s;
int f(int a,int b){
int l[4],r=0;
l[0]=0;l[1]=0;l[2]=0;l[3]=0;
l[a&3]++;l[a>>2]++;l[b]++;
for(int i=1;i<=3;i++)r+=(l[i]>0);
return r;
}
int rec(int i,int l,int r){
if(i==x)return 0;
if(~dp[i][l][r])return dp[i][l][r];
int c1=f(l,mp[s[i]]),c2=f(r,mp[s[i]]);
return dp[i][l][r]=max(rec(i+1,(l>>2)|(mp[s[i]]<<2),r)+c1,rec(i+1,l,(r>>2)|(mp[s[i]]<<2))+c2);
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
memset(dp,-1,sizeof(dp));
mp['M']=1;mp['F']=2;mp['B']=3;
cin>>x>>s;
cout<<rec(0,0,0);
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... |