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>
#define int long long
using namespace std;
const int N = 2e5, POS = 256, INF = 1e9;
int n, f[N], val[N][POS];
signed main() {
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
*/
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++) {
char c; cin >> c;
if(c == 'M') f[i] = 1;
if(c == 'F') f[i] = 2;
if(c == 'B') f[i] = 3;
}
for(int i = 0; i < N; i++)
for(int j = 0; j < POS; j++)
val[i][j] = -INF;
val[0][0] = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < POS; j++) {
int p[4], sit = j;
for(int k = 0; k < 4; k++, sit /= 4)
p[k] = sit % 4;
int t1 = 1, t2 = 1;
if(f[i] != p[0] && p[0] != 0) t1++;
if(f[i] != p[2] && p[2] != 0) t2++;
if(f[i] != p[1] && p[0] != p[1] && p[1] != 0) t1++;
if(f[i] != p[3] && p[2] != p[3] && p[3] != 0) t2++;
int j1 = p[1] + 4*f[i] + 16*p[2] + 64*p[3],
j2 = p[0] + 4*p[1] + 16*p[3] + 64*f[i];
val[i+1][j1] = max(val[i+1][j1], val[i][j] + t1);
val[i+1][j2] = max(val[i+1][j2], val[i][j] + t2);
}
}
int maxi = 0;
for(int j = 0; j < POS; j++)
maxi = max(maxi, val[n][j]);
cout << maxi;
}
# | 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... |