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;
int dp[4][4][4][4], newDp[4][4][4][4];
bitset<3> ap;
void maxSelf(int &x, int y) {
if (x < y) {
x = y;
}
}
void testCase() {
int n;
string s;
cin >> n >> s;
for (int a = 0; a < 4; ++a) {
for (int b = 0; b < 4; ++b) {
for (int c = 0; c < 4; ++c) {
for (int d = 0; d < 4; ++d) {
newDp[a][b][c][d] = -1;
}
}
}
}
newDp[0][0][0][0] = 0;
for (char ch : s) {
int nxt = 1;
if (ch == 'F') {
nxt = 2;
}
if (ch == 'B') {
nxt = 3;
}
for (int a = 0; a < 4; ++a) {
for (int b = 0; b < 4; ++b) {
for (int c = 0; c < 4; ++c) {
for (int d = 0; d < 4; ++d) {
dp[a][b][c][d] = newDp[a][b][c][d];
newDp[a][b][c][d] = -1;
}
}
}
}
for (int a = 0; a < 4; ++a) {
for (int b = 0; b < 4; ++b) {
for (int c = 0; c < 4; ++c) {
for (int d = 0; d < 4; ++d) {
if (dp[a][b][c][d] != -1) {
ap[0] = ap[1] = ap[2] = false;
if (a) {
ap[a - 1] = true;
}
if (b) {
ap[b - 1] = true;
}
ap[nxt - 1] = true;
maxSelf(newDp[b][nxt][c][d], dp[a][b][c][d] + ap.count());
ap[0] = ap[1] = ap[2] = false;
if (c) {
ap[c - 1] = true;
}
if (d) {
ap[d - 1] = true;
}
ap[nxt - 1] = true;
maxSelf(newDp[a][b][d][nxt], dp[a][b][c][d] + ap.count());
}
}
}
}
}
}
int ans = 0;
for (int a = 0; a < 4; ++a) {
for (int b = 0; b < 4; ++b) {
for (int c = 0; c < 4; ++c) {
for (int d = 0; d < 4; ++d) {
maxSelf(ans, newDp[a][b][c][d]);
}
}
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
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... |