This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int INF=1e9+7;
int dp[4][4][4][4], tmp[4][4][4][4], T[3];
int ile(int a, int b, int c) {
T[0]=a;
T[1]=b;
T[2]=c;
if(T[2]<T[1]) swap(T[2], T[1]);
if(T[1]<T[0]) swap(T[0], T[1]);
if(T[2]<T[1]) swap(T[2], T[1]);
int ans=1;
if(T[0]==0) ans=0;
if(T[1]!=T[0]) ++ans;
if(T[2]!=T[1]) ++ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
string s;
cin >> n >> s;
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) dp[a][b][c][d]=-INF;
dp[0][0][0][0]=0;
for(auto i : s) {
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) tmp[a][b][c][d]=-INF;
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) {
int x=1;
if(i=='F') x=2;
else if(i=='B') x=3;
tmp[a][b][d][x]=max(tmp[a][b][d][x], dp[a][b][c][d]+ile(c, d, x));
tmp[b][x][c][d]=max(tmp[b][x][c][d], dp[a][b][c][d]+ile(a, b, x));
}
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) dp[a][b][c][d]=tmp[a][b][c][d];
}
int ans=0;
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) ans=max(ans, dp[a][b][c][d]);
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... |