# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
98325 | rosi | Miners (IOI07_miners) | C++14 | 32 ms | 896 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
const int inf = -1;
int dp[2][4][4][4];
int shipment[MAX_N];
char s[MAX_N];
int n;
int goat(int a, int b, int c) {
int ret = 0;
if (a == 1 || b == 1 || c == 1) {
ret++;
}
if (a == 2 || b == 2 || c == 2) {
ret++;
}
if (a == 3 || b == 3 || c == 3) {
ret++;
}
return ret;
}
void Max(int &a, int b) {
a = max(a, b);
}
void dynamicProgramming() {
for (int a = 0; a <= 3; a++) {
for (int b = 0; b <= 3; b++) {
for (int c = 0; c <= 3; c++) {
dp[0][a][b][c] = inf;
}
}
}
dp[0][0][0][0] = 0;
int res = 0;
for (int i = 0; i <= n; i++) {
int cur = i & 1;
int nxt = !cur;
for (int a = 0; a <= 3; a++) {
for (int b = 0; b <= 3; b++) {
for (int c = 0; c <= 3; c++) {
dp[nxt][a][b][c] = inf;
}
}
}
for (int a = 0; a <= 3; a++) {
for (int b = 0; b <= 3; b++) {
for (int c = 0; c <= 3; c++) {
if (dp[cur][a][b][c] == inf) {
continue;
}
int val = dp[cur][a][b][c];
res = max(res, val);
Max(dp[nxt][shipment[i]][b][c], val + goat(a, shipment[i], shipment[i + 1]));
Max(dp[nxt][c][a][shipment[i]], val + goat(b, c, shipment[i + 1]));
}
}
}
}
printf("%d", res);
}
int main () {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
scanf("%d", &n);
scanf("%s", s);
for (int i = 1; i <= n; i++) {
if (s[i - 1] == 'M') {
shipment[i] = 1;
}
else if (s[i - 1] == 'F') {
shipment[i] = 2;
}
else {
shipment[i] = 3;
}
}
dynamicProgramming();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |