이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |