이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
const int maxn = 1e5 + 20;
int a[maxn];
int dp[maxn][4][4][4][4];
int cnt(int x, int y, int z) {
if (x == 0 && y == 0) {
return 1;
}
if (x == 0) {
if (y == z) {
return 1;
}
else {
return 2;
}
}
if (x == y && y == z) {
return 1;
}
if (x == y || y == z || z == x) {
return 2;
}
return 3;
}
void just_do_it() {
fill_n(&dp[0][0][0][0][0], maxn * 4 * 4 * 4 * 4, -1);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
char c;
cin >> c;
if (c == 'M') {
a[i] = 1;
}
if (c == 'F') {
a[i] = 2;
}
if (c == 'B') {
a[i] = 3;
}
}
dp[0][0][0][0][0] = 0;
int res = 0;
for (int i = 0; i < n; i++) {
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
for (int z = 0; z < 4; z++) {
for (int w = 0; w < 4; w++) {
if (dp[i][x][y][z][w] == -1) {
continue;
}
int t = a[i + 1];
dp[i + 1][y][t][z][w] = max(dp[i + 1][y][t][z][w], dp[i][x][y][z][w] + cnt(x, y, t));
dp[i + 1][x][y][w][t] = max(dp[i + 1][x][y][w][t], dp[i][x][y][z][w] + cnt(z, w, t));
res = max(res, dp[i + 1][y][t][z][w]);
res = max(res, dp[i + 1][x][y][w][t]);
}
}
}
}
}
cout << res;
}
# | 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... |