이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
const ll mod=1e9+7;
#define endl '\n'
ll n;
string s;
map<pair<ll,pair<pair<ll,ll>,pair<ll,ll>>>,ll>dp;
ll fun(ll idx,ll p,ll p1,ll p2,ll p3)
{
if(idx==n)
{
return 0;
}
if(dp[{idx,{{p,p1},{p2,p3}}}]!=0)return dp[{idx,{{p,p1},{p2,p3}}}];
ll o=1;
if(s[idx]=='F')o=3;
else if(s[idx]=='B')o=2;
ll ans=1;
if(p!=0&&p!=o)ans++;
if(p1!=0&&p1!=o)ans++;
if(p1!=0&&p1==p&&o!=p)ans--;
ll c1=fun(idx+1,o,p,p2,p3)+ans;
ans=1;
if(p2!=0&&p2!=o)ans++;
if(p3!=0&&p3!=o)ans++;
if(p2!=0&&p2==p3&&o!=p2)ans--;
ll c2=0;
if(idx!=0)
c2=fun(idx+1,p,p1,o,p2)+ans;
return dp[{idx,{{p,p1},{p2,p3}}}]=max(c1,c2);
}
int32_t main()
{
//freopen("jumping.in","r",stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>s;
cout<<fun(0,0,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... |