이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int dp[100005][4][4][4][4];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
string s; cin >> s;
memset(dp, -1, sizeof(dp));
dp[0][3][3][3][3] = 0;
for (int i = 0; i < n; ++i) {
for (int a1 = 0; a1 < 4; ++a1) {
for (int a2 = 0; a2 < 4; ++a2) {
for (int b1 = 0; b1 < 4; ++b1) {
for (int b2 = 0; b2 < 4; ++b2) {
if (dp[i][a1][a2][b1][b2] < 0) continue;
int cur = (s[i] == 'M' ? 0 : (s[i] == 'F' ? 1 : 2));
int amask = (((1 << cur) | (1 << a1)) | (1 << a2));
if (amask >= 8) amask -= 8;
int acnt = __builtin_popcount(amask);
int bmask = (((1 << cur) | (1 << b1)) | (1 << b2));
if (bmask >= 8) bmask -= 8;
int bcnt = __builtin_popcount(bmask);
dp[i + 1][a2][cur][b1][b2] = max(dp[i + 1][a2][cur][b1][b2],
dp[i][a1][a2][b1][b2] + acnt);
dp[i + 1][a1][a2][b2][cur] = max(dp[i + 1][a1][a2][b2][cur],
dp[i][a1][a2][b1][b2] + bcnt);
}
}
}
}
}
int ans = 0;
for (int a1 = 0; a1 < 4; ++a1) {
for (int a2 = 0; a2 < 4; ++a2) {
for (int b1 = 0; b1 < 4; ++b1) {
for (int b2 = 0; b2 < 4; ++b2) {
ans = max(ans, dp[n][a1][a2][b1][b2]);
}
}
}
}
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... |