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