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