이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define rsz resize
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define f first
#define s second
const int N = 100000;
int dp[2][4][4][4][4];
int unique(int a, int b, int c) {
if (a == 0 && b == 0)
return 1;
if (a == 0 || a == b)
return 1 + (b != c);
return 2 + (a != c && b != c);
}
bool ckmax(int& a, const int& b) {
return (a < b ? a = b, true : false);
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
int n; string s;
cin >> n >> s;
memset(dp[0], -0x3f, sizeof(dp[0]));
dp[0][0][0][0][0] = 0;
for (char ch : s) {
int i = ch == 'M' ? 1 : (ch == 'F' ? 2 : 3);
memset(dp[1], -0x3f, sizeof(dp[1]));
for (int a = 0; a < 4; ++a)
for (int b = 0; b < 4; ++b)
for (int c = 0; c < 4; ++c)
for (int d = 0; d < 4; ++d) {
ckmax(dp[1][b][i][c][d], dp[0][a][b][c][d] + unique(a, b, i));
ckmax(dp[1][a][b][d][i], dp[0][a][b][c][d] + unique(c, d, i));
}
swap(dp[0], dp[1]);
}
int ans = 0;
for (int a = 0; a < 4; ++a)
for (int b = 0; b < 4; ++b)
for (int c = 0; c < 4; ++c)
for (int d = 0; d < 4; ++d)
ckmax(ans, dp[0][a][b][c][d]);
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... |