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 m[3] = {a, b, c};
sort(m, m+3);
return -(m[2] == 3) + (unique(m, m+3) - m);
}
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(c);
c[3][3][3][3] = 0;
for(int i=0, j; i<n; ++i){
cin >> inp; j = (inp > 'B') + (inp > 'F');
swap(c, dp);
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));
remax(ans, 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... |