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