이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
const int MAXN = 1e5+7;
int A[MAXN];
int DP[2][4][4][4][4];
int check(int a, int b, int c){
int result = 0;
for(int i = 1; i <= 3; i++){
if(a == i || b == i || c == i){
result++;
}
}
return result;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
string ciag;
cin >> n;
cin >> ciag;
for(int i = 0; i < n; i++){
if(ciag[i] == 'M'){
A[i+1] = 1;
}else if(ciag[i] == 'F'){
A[i+1] = 2;
}else{
A[i+1] = 3;
}
}
int obecny = 0;
int drugi = 1;
for(int i = n; i >= 0; i--){
for(int a = 0; a <= 3; a++){
for(int b = 0; b <= 3; b++){
for(int c = 0; c<=3; c++){
for(int d = 0; d <= 3; d++){
DP[obecny][a][b][c][d] = max(DP[drugi][b][A[i]][c][d] + check(a, b, A[i]), DP[drugi][a][b][d][A[i]] + check(c, d, A[i]));
}
}
}
}
swap(obecny, drugi);
}
cout << DP[obecny][0][0][0][0];
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... |