이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1;
int dp[maxn][4][4][4][4];
bool ready[maxn][4][4][4][4];
string s;
int n;
int get_num(char c) {
if (c == 'M')
return 1;
if (c == 'F')
return 2;
else
return 3;
}
int get_score(int a, int b, int c) {
if (a == 0) {
if (b == 0) {
if (c == 0)
return 0;
return 1;
} else {
if (b == c)
return 1;
return 2;
}
} else {
if (a == b) {
if (b == c)
return 1;
return 2;
} else {
if (a == c) {
return 2;
} else {
if (b == c)
return 2;
return 3;
}
}
}
}
int solve(int i, int a, int b, int c, int d) {
if (i > n)
return 0;
if (ready[i][a][b][c][d])
return dp[i][a][b][c][d];
int ans = 0;
int x = get_num(s[i]);
int score1 = get_score(a, b, x);
int score2 = get_score(c, d, x);
ans = max({ans, solve(i+1, b, x, c, d) + score1, solve(i+1, a, b, d, x) + score2});
ready[i][a][b][c][d] = true;
dp[i][a][b][c][d] = ans;
return ans;
}
int main() {
cin >> n >> s;
s = "." + s;
cout << solve(1, 0, 0, 0, 0) << '\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... |