이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
int dp[2][4][4][4][4];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n;
int tt = 0;
for (int t = 0; t < 2; t++){
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
for (int ii = 0; ii < 4; ii++){
for (int jj = 0; jj < 4; jj++){
dp[t][i][j][ii][jj] = -1e9;
}
}
}
}
}
dp[0][0][0][0][0] = 0;
while(n--){
char c;
cin >> c;
int cur = 0;
if (c == 'M')
cur = 1; else
if (c == 'B')
cur = 2; else
cur = 3;
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
for (int ii = 0; ii < 4; ii++){
for (int jj = 0; jj < 4; jj++){
dp[tt^1][i][j][ii][jj] = -1e9;
}
}
}
}
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
for (int ii = 0; ii < 4; ii++){
for (int jj = 0; jj < 4; jj++){
{
int a = i, b = j, c = cur;
if (a > b)
swap(a, b);
if (b > c)
swap(b, c);
if (a > b)
swap(a, b);
int kol = 1;
if (a != b && a != 0)
++kol;
if (b != c && b != 0)
++kol;
dp[tt^1][j][cur][ii][jj] = max(dp[tt^1][j][cur][ii][jj], dp[tt][i][j][ii][jj]+kol);
}
{
int a = ii, b = jj, c = cur;
if (a > b)
swap(a, b);
if (b > c)
swap(b, c);
if (a > b)
swap(a, b);
int kol = 1;
if (a != b && a != 0)
++kol;
if (b != c && b != 0)
++kol;
dp[tt^1][i][j][jj][cur] = max(dp[tt^1][i][j][jj][cur], dp[tt][i][j][ii][jj]+kol);
}
}
}
}
}
tt^=1;
}
int ans = 0;
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
for (int ii = 0; ii < 4; ii++){
for (int jj = 0; jj < 4; jj++){
ans = max(ans, dp[tt][i][j][ii][jj]);
}
}
}
}
cout << ans;
}
# | 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... |