This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
const int inf = (int) 1e9;
vector dp(4, vector(4, vector(4, vector<int>(4, -inf))));
dp[0][0][0][0] = 0;
for (int id = 0; id < n; id++) {
vector new_dp(4, vector(4, vector(4, vector<int>(4, -inf))));
int x = (s[id] == 'M' ? 1 : (s[id] == 'F' ? 2 : 3));
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
int c = 0;
c |= 1 << x;
c |= 1 << i;
c |= 1 << j;
c &= ~1;
new_dp[x][i][k][l] = max(new_dp[x][i][k][l], dp[i][j][k][l] + __builtin_popcount(c));
c = 0;
c |= 1 << x;
c |= 1 << k;
c |= 1 << l;
c &= ~1;
new_dp[i][j][x][k] = max(new_dp[i][j][x][k], dp[i][j][k][l] + __builtin_popcount(c));
}
}
}
}
swap(dp, new_dp);
}
int ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
ans = max(ans, dp[i][j][k][l]);
}
}
}
}
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... |