이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
const int INF = 1e9;
int ckmax(int &a, int b){return (b>a)?a=b:b;}
int n;
string s;
int dp[2][4][4][4][4];
int main(){
// freopen("a.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> s; s = "$"+s;
for(int i = 1; i<=n; i++)
if(s[i] == 'M') s[i] = '1';
else if(s[i] == 'F') s[i] = '2';
else s[i] = '3';
memset(dp, -1, sizeof dp);
dp[0][0][0][0][0] = 0;
for(int i = 1; i<=n; i++){
memset(dp[1], -1, sizeof dp[1]);
int x = s[i]-'0';
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(dp[0][a][b][c][d] == -1) continue;
if(a!=b && a!= x && b != x && a != 0 && b != 0)
ckmax(dp[1][b][x][c][d], dp[0][a][b][c][d]+3);
else if((a == b && b == x)||(a == 0 && b == x)||(b == 0 && a == x)||(a == 0 && b == 0))
ckmax(dp[1][b][x][c][d], dp[0][a][b][c][d]+1);
else
ckmax(dp[1][b][x][c][d], dp[0][a][b][c][d]+2);
if(c!=d && c!= x && d != x && c != 0 && d != 0)
ckmax(dp[1][a][b][d][x], dp[0][a][b][c][d]+3);
else if((c == d && d == x)||(c == 0 && d == x)||(d == 0 && c == x)||(c == 0 && d == 0))
ckmax(dp[1][a][b][d][x], dp[0][a][b][c][d]+1);
else
ckmax(dp[1][a][b][d][x], dp[0][a][b][c][d]+2);
}
swap(dp[0], dp[1]);
}
int ans = 0;
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++)
ckmax(ans, dp[0][a][b][c][d]);
cout << ans << endl;
}
# | 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... |