이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e5+5;
int dp[2][4][4][4][4];
const int INF = 1e9+7;
int f(int a, int b, int c) {
int s = 0;
for(int i = 1; i <= 3; ++i)
if(a == i || b == i || c == i) s++;
return s;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
memset(dp, -INF, sizeof(dp));
int n; cin >> n;
string s; cin >> s;
vector<int>a(n);
for (int i = 0; i < n; ++i) {
if (s[i] == 'M') a[i] = 1;
else if (s[i] == 'F') a[i] = 2;
else if (s[i] == 'B') a[i] = 3;
}
dp[1][0][0][0][0] = 0;
int ans = 0;
for (int i = 0; i <n; ++i) {
bool ic = i%2;
int p = a[i];
//cerr << p << " ";
for (int j = 0; j <= 3; ++j) {for (int k = 0; k <= 3; ++k) {
for (int l = 0; l <= 3; ++l) {for (int m = 0; m <= 3; ++m) {
int inc = f(p,j,k);
//if (p == 0 || j == 0 || k == 0) inc--;
dp[ic][p][j][l][m] = max(dp[ic][p][j][l][m],
inc+dp[ic^1][j][k][l][m]);
dp[ic][l][m][p][j] = max(dp[ic][l][m][p][j],
inc+dp[ic^1][l][m][j][k]);
}
}
}
}
}
for (int j = 0; j <= 3; ++j) {for (int k = 0; k <= 3; ++k) {
for (int l = 0; l <= 3; ++l) {for (int m = 0; m <= 3; ++m) {
ans = max(ans, dp[0][j][k][l][m]);
ans = max(ans, dp[1][j][k][l][m]);
}}}}
cout << ans << "\n";
return 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... |