이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int dp[2][4][4][4][4];
int f(int a, int b, int c){
return (a == 1 || b == 1 || c == 1) + (a == 2 || b == 2 || c == 2) + (a == 3 || b == 3 || c == 3);
}
int main()
{
int N;
cin >> N;
string s;
cin >> s;
vector<int> v(N);
for(int i = 0; i < N ; i++){
v[i] = (s.substr(i, 1) == "M" ? 1 : (s.substr(i, 1) == "F" ? 2 : 3));
}
int x = 1, l = 0;
for(int i = N-1; i >= 0; i --){
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 ++){
int e = v[i];
dp[x][a][b][c][d] = max(dp[l][b][e][c][d] + f(a,b,e), dp[l][a][b][d][e] + f(c,d,e));
}
}
}
}
x ^= 1;
l ^= 1;
}
cout << dp[l][0][0][0][0] << 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... |