이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0, dp[2][4][4][4][4] = {}, reset[4][4][4][4];
cin >> n;
string s;
cin >> s;
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)
reset[i][j][k][l] = -1e9;
memcpy(dp[1], reset, sizeof(reset));
dp[1][0][0][0][0] = 0;
for (int i = 0; i < n; ++i) {
int cur = s[i] == 'M' ? 1 : s[i] == 'F' ? 2 : 3;
auto cost = [&](int x, int y, int z) {
int cnt[4] = {}, ans = 0;
++cnt[x], ++cnt[y], ++cnt[z];
for (int i = 1; i < 4; ++i)
ans += !!cnt[i];
return ans;
};
memcpy(dp[i & 1], reset, sizeof(reset));
for (int fll = 0; fll < 4; ++fll)
for (int fl = !!fll; fl < 4; ++fl)
for (int sll = 0; sll < 4; ++sll)
for (int sl = !!sll; sl < 4; ++sl) {
dp[i & 1][fl][cur][sll][sl] = max(dp[i & 1][fl][cur][sll][sl], dp[(i & 1) ^ 1][fll][fl][sll][sl] + cost(fll, fl, cur));
dp[i & 1][fll][fl][sl][cur] = max(dp[i & 1][fll][fl][sl][cur], dp[(i & 1) ^ 1][fll][fl][sll][sl] + cost(sll, sl, cur));
ans = max({ans, dp[i & 1][fl][cur][sll][sl],dp[i & 1][fll][fl][sl][cur]});
}
}
cout << ans;
}
# | 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... |