# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98325 | rosi | Miners (IOI07_miners) | C++14 | 32 ms | 896 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
Compilation message (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... |