이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
using namespace std;
int dp[100010][4][4][4][4], moze[100010][4][4][4][4];
int cal(int a, int b, int c){
int val[4] = {0, 0, 0};
val[a] = 1; val[b] = 1; val[c] = 1;
return val[1] + val[2] + val[3];
}
int main(){
int n; string s;
cin >> n >> s;
s = '.' + s;
memset(dp, 0, sizeof dp); memset(moze, false, sizeof moze);
moze[0][0][0][0][0] = true;
int ans = 0;
for (int i = 1; i <= n; i++){
int x = 1;
if (s[i] == 'B')
x = 2;
else if (s[i] == 'F')
x = 3;
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++){
if (!moze[i - 1][a][b][c][d])
continue;
moze[i][x][a][c][d] = true;
moze[i][a][b][x][c] = true;
dp[i][x][a][c][d] = max(dp[i][x][a][c][d], dp[i - 1][a][b][c][d] + cal(x, a, b));
dp[i][a][b][x][c] = max(dp[i][a][b][x][c], dp[i - 1][a][b][c][d] + cal(x, c, d));
ans = max(ans, max(dp[i][x][a][c][d] , dp[i][a][b][x][c]));
}
}
}
}
}
cout << ans << endl;
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... |