이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int dp[100005][4][4][4][4], n, ans;
string st;
int main (){
cin >> n >> st;
memset(dp, -1, sizeof dp);
dp[0][0][0][0][0] = 0;
for (int i = 1;i <= n;i++){
int f;
if (st[i - 1] == 'M') f = 2;
if (st[i - 1] == 'B') f = 4;
if (st[i - 1] == 'F') f = 8;
for (int m11 = 0;m11 < 4;m11++)
for (int m12 = 0;m12 < 4;m12++)
for (int m21 = 0;m21 < 4;m21++)
for (int m22 = 0;m22 < 4;m22++)
if (dp[i - 1][m11][m12][m21][m22] != -1){
int job = dp[i - 1][m11][m12][m21][m22];
int s1 = 0, s2 = 0;
int c1 = (1<<m11) | (1<<m12) | f;
int c2 = (1<<m21) | (1<<m22) | f;
for (int bit = 1;bit < 4;bit++){
if ((1<<bit) & c1) s1++;
if ((1<<bit) & c2) s2++;
}
int to = log2(f);
dp[i][m12][to][m21][m22] = max(dp[i][m12][to][m21][m22], job + s1);
dp[i][m11][m12][m22][to] = max(dp[i][m11][m12][m22][to], job + s2);
ans = max({ans, job + s1, job + s2});
}
}
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... |