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;
#define F(z) for(int z=0; z<4; ++z)
#define remax(x, y) x = max(x, y)
#define fill(z) F(a) F(b) F(x) F(y) z[a][b][x][y] = -2e9
int cost(int a, int b, int c){
int res = 0;
for(int i : {0, 1, 2}) res += (a == i) || (b == i) || (c == i);
return res;
}
int n, dp[4][4][4][4], c[4][4][4][4], ans;
char inp;
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
fill(dp);
dp[3][3][3][3] = 0;
for(int i=0, j; i<n; ++i){
cin >> inp; j = (inp > 'B') + (inp > 'F');
fill(c);
for(int k : {j, 3}) F(a) F(b) F(x) F(y){
remax(c[b][k][x][y], dp[a][b][x][y] + cost(a, b, k));
remax(c[a][b][y][k], dp[a][b][x][y] + cost(x, y, k));
}
F(a) F(b) F(x) F(y)
remax(ans, dp[a][b][x][y] = c[a][b][x][y]);
}
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... |