이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
const int maxn=1e5 + 10;
int di[4]={1,-1,0,0};
int dj[4]={0,0,-1,1};
int n;
string s;
int dp[maxn][4][4][4][4];
int f(int idx,int a,int b,int c,int d)
{
if(idx==n)
{
return 0;
}
if(dp[idx][a][b][c][d]!=-1)return dp[idx][a][b][c][d];
int rez=0;
int x=0;
if(s[idx]=='M')
{
x=1;
}
else if(s[idx]=='F')
{
x=2;
}
else
{
x=3;
}
set<int>se1;
se1.insert(a);
se1.insert(b);
se1.insert(x);
set<int>se2;
se2.insert(c);
se2.insert(d);
se2.insert(x);
int num=se1.size();
if(a==0 || b==0)
{
num--;
}
rez=max(rez, f(idx+1,b,x,c,d)+num);
num=se2.size();
if(c==0 || d==0)
{
num--;
}
rez=max(rez, f(idx+1,a,b,d,x)+num);
return dp[idx][a][b][c][d]=rez;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin>>n>>s;
memset(dp,-1,sizeof dp);
cout<<f(0,0,0,0,0)<<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... |