이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n;
int food[100002];
bool v[100002][4][4][4][4];
int dp[100002][4][4][4][4];
int diff(int a, int b, int c){
int cont = 1;
if(a > c){
swap(a, c);
}
if(a > b){
swap(a, b);
}
if(b > c){
swap(b, c);
}
if(a != b){
cont++;
}
if(c != b){
cont++;
}
if(a == 0){
cont--;
}
return cont;
}
int coal(int i, int x1, int x2, int y1, int y2){
if(i == n + 1) return 0;
if(!v[i][x1][x2][y1][y2]){
v[i][x1][x2][y1][y2] = true;
int aux = max(coal(i + 1, food[i], x1, y1, y2) + diff(food[i], x1, x2),
coal(i + 1, x1, x2, food[i], y1) + diff(food[i], y1, y2));
dp[i][x1][x2][y1][y2] = aux;
}
return dp[i][x1][x2][y1][y2];
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i){
char asd;
cin >> asd;
if(asd == 'F'){
food[i] = 1;
}else{
if(asd == 'M'){
food[i] = 2;
}else{
food[i] = 3;
}
}
}
cout << coal(1, 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... |