# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
346424 | dgq | Miners (IOI07_miners) | C++17 | 316 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 N = 1e5;
int food[N + 1], dp[2][4][4][4][4];
char str[N + 1];
int nFood;
int score(int a, int b, int c) {
int ans = 0;
if (a == 1 || b == 1 || c == 1) {
++ans;
}
if (a == 2 || b == 2 || c == 2) {
++ans;
}
if (a == 3 || b == 3 || c == 3) {
++ans;
}
return ans;
}
int main() {
scanf("%d", &nFood);
scanf(" %s", str);
for (int i = 1; i <= nFood; ++i) {
char foodchar = str[i - 1];
switch(foodchar) {
case 'M':
food[i] = 1;
break;
case 'F':
food[i] = 2;
break;
case 'B':
food[i] = 3;
break;
}
}
for (int i = nFood + 1; i >= 1; --i) {
for (int x1 = 0; x1 <= 3; ++x1) {
for (int x2 = 0; x2 <= 3; ++x2) {
for (int y1 = 0; y1 <= 3; ++y1) {
for (int y2 = 0; y2 <= 3; ++y2) {
int curr = i % 2;
int next = curr ^ 1;
if (i == nFood + 1) {
dp[curr][x1][x2][y1][y2] = 0;
} else {
int send_to_mine1 =
score(x1, x2, food[i]) + dp[next][food[i]][x1][y1][y2];
int send_to_mine2 =
score(y1, y2, food[i]) + dp[next][x1][x2][food[i]][y1];
dp[curr][x1][x2][y1][y2] = max(send_to_mine1, send_to_mine2);
}
}
}
}
}
}
cout << dp[1][0][0][0][0];
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... |