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>
#pragma GCC optimize ("O4")
#pragma GCC optimize ("fast-math")
#pragma GCC optimize ("unroll-loops")
using namespace std;
#define int long long
#define ll long long
#define xx first
#define yy second
#define all (x) begin(x), end(x)
int n;
const int NMAX = 1e5;
const int VMAX = 3;
int v[NMAX + 1];
int dp[VMAX][VMAX + 1][VMAX + 1][VMAX + 1][VMAX + 1];
int eg (int a, int b, int c)
{
int k = 0;
for (int i = 1; i <= 3; ++ i){
if ((a == i) || (b == i) || (c == i))
k ++;
}
return k;
}
signed main(void){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++ i){
char s;
cin >> s;
if (s == 'M')
v[i] = 1;
if (s == 'F')
v[i] = 2;
if (s == 'B')
v[i] = 3;
}
int x = 1, y = 0;
for (int i = n; i >= 0; -- i){
swap (x, y);
for (int j = 0; j <= VMAX; ++ j){
for (int k = 0; k <= VMAX; ++ k){
for (int l = 0; l <= VMAX; ++ l)
{
for (int m = 0; m <= VMAX; ++ m){
dp[x][j][k][l][m] = max (dp[y][k][v[i]][l][m] + eg(j, k, v[i]), dp[y][j][k][m][v[i]] + eg(l, m, v[i]));
}
}
}
}
}
cout << dp[x][0][0][0][0];
return 0 ^ 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... |