이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ar array
const int INF = 1e17;
const int MOD = 998244353;
const int MXN = 1e5+9;
int dp[MXN][3][3][3][3];
void amax(int &a, int b) { a = max(a, b); }
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie();
int n; string s; cin>>n>>s;
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++)
dp[0][j][k][l][m] = -6;
for (int i = 1; i <= n; i++) {
int cur = -1;
if (s[i-1] == 'M') cur = 0;
if (s[i-1] == 'F') cur = 1;
if (s[i-1] == 'B') cur = 2;
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++)
dp[i][j][k][l][m] = -INF;
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 x1 = set<int>{j,k,cur}.size();
int x2 = set<int>{l,m,cur}.size();
amax(dp[i][k][cur][l][m], dp[i-1][j][k][l][m] + x1);
amax(dp[i][j][k][m][cur], dp[i-1][j][k][l][m] + x2);
}
}
}
}
}
int ans = -INF;
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++)
amax(ans, dp[n][j][k][l][m]);
cout<<ans<<"\n";
}
# | 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... |