답안 #680286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680286 2023-01-10T13:16:22 Z mjhmjh1104 Tortoise (CEOI21_tortoise) C++17
18 / 100
94 ms 8328 KB
#include <map>
#include <tuple>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int n, a[500006], dist[500006], res;
vector<int> playgrounds;
int pv[500006], nx[500006];

map<tuple<int, int, int, int, int>, int> mem;

int f(int x, int y, int z, int w, int p) {
    if (y > 2 * n - 2) return 0;
    if (mem.find({ x, y, z, w, p }) != mem.end()) return mem[{ x, y, z, w, p }];
    if (w && a[x] == -1) return f(x, y, z, 0, p);
    int res = 0;
    if (w && a[x] != -1) res = max(res, f(x + 1, y - 1, min(n, max(a[x + 1], 0)), 1, p));
    if (x < n - 1) res = max(res, f(x + 1, y + 1, min(n, max(a[x + 1], 0)), 0, p));
    if (pv[x] != -1 && z > 0 && y <= 2 * x) {
        int dist = x - pv[x];
        int N = min(z, (2 * x - y) / (2 * dist) + 1);
        res = max(res, f(x, y + 2 * dist * N, z - N, 0, p) + N);
        if (!p) for (int i = 1; i <= N; i++) res = max(res, f(x, y + 2 * dist * i, z - i, 0, 1) + i);
    }
    if (nx[x] != -1 && z > 0 && y <= 2 * x) {
        int dist = nx[x] - x;
        int N = min(z, (2 * x - y) / (2 * dist) + 1);
        res = max(res, f(x, y + 2 * dist * N, z - N, 1, p) + N);
        if (!p) for (int i = 1; i <= N; i++) res = max(res, f(x, y + 2 * dist * i, z - i, 0, 1) + i);
    }
    return mem[{ x, y, z, w, p }] = res;
}

int main() {
    scanf("%d", &n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
        sum += max(a[i], 0);
        dist[i] = (int)1e9;
        if (a[i] < 0) playgrounds.push_back(i);
    }
    for (int i = 0; i < n; i++) {
        int it = lower_bound(playgrounds.begin(), playgrounds.end(), i) - playgrounds.begin();
        if (it == (int)playgrounds.size()) nx[i] = -1;
        else nx[i] = playgrounds[it];
        it = upper_bound(playgrounds.begin(), playgrounds.end(), i) - playgrounds.begin() - 1;
        if (it == -1) pv[i] = -1;
        else pv[i] = playgrounds[it];
    }
    {
        int tmp = (int)1e9;
        for (int i = 0; i < n; i++) {
            if (a[i] == -1) tmp = 0;
            dist[i] = min(dist[i], tmp);
            tmp++;
        }
        tmp = (int)1e9;
        for (int i = n - 1; i >= 0; i--) {
            if (a[i] == -1) tmp = 0;
            dist[i] = min(dist[i], tmp);
            tmp++;
        }
    }
    printf("%lld", sum - f(0, 0, min(n, max(a[0], 0)), 0, 0));
}

Compilation message

tortoise.cpp: In function 'int main()':
tortoise.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
tortoise.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%d", a + i);
      |         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 292 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 292 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 52 ms 5200 KB Output is correct
28 Correct 94 ms 8328 KB Output is correct
29 Correct 66 ms 6992 KB Output is correct
30 Correct 43 ms 4980 KB Output is correct
31 Correct 59 ms 6656 KB Output is correct
32 Correct 45 ms 4244 KB Output is correct
33 Correct 61 ms 6732 KB Output is correct
34 Correct 67 ms 5548 KB Output is correct
35 Correct 60 ms 6260 KB Output is correct
36 Correct 50 ms 5928 KB Output is correct
37 Correct 55 ms 6272 KB Output is correct
38 Correct 53 ms 6324 KB Output is correct
39 Correct 59 ms 6732 KB Output is correct
40 Correct 51 ms 5892 KB Output is correct
41 Correct 52 ms 6020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 292 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 52 ms 5200 KB Output is correct
28 Correct 94 ms 8328 KB Output is correct
29 Correct 66 ms 6992 KB Output is correct
30 Correct 43 ms 4980 KB Output is correct
31 Correct 59 ms 6656 KB Output is correct
32 Correct 45 ms 4244 KB Output is correct
33 Correct 61 ms 6732 KB Output is correct
34 Correct 67 ms 5548 KB Output is correct
35 Correct 60 ms 6260 KB Output is correct
36 Correct 50 ms 5928 KB Output is correct
37 Correct 55 ms 6272 KB Output is correct
38 Correct 53 ms 6324 KB Output is correct
39 Correct 59 ms 6732 KB Output is correct
40 Correct 51 ms 5892 KB Output is correct
41 Correct 52 ms 6020 KB Output is correct
42 Correct 18 ms 2388 KB Output is correct
43 Incorrect 30 ms 3228 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 292 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 52 ms 5200 KB Output is correct
28 Correct 94 ms 8328 KB Output is correct
29 Correct 66 ms 6992 KB Output is correct
30 Correct 43 ms 4980 KB Output is correct
31 Correct 59 ms 6656 KB Output is correct
32 Correct 45 ms 4244 KB Output is correct
33 Correct 61 ms 6732 KB Output is correct
34 Correct 67 ms 5548 KB Output is correct
35 Correct 60 ms 6260 KB Output is correct
36 Correct 50 ms 5928 KB Output is correct
37 Correct 55 ms 6272 KB Output is correct
38 Correct 53 ms 6324 KB Output is correct
39 Correct 59 ms 6732 KB Output is correct
40 Correct 51 ms 5892 KB Output is correct
41 Correct 52 ms 6020 KB Output is correct
42 Correct 18 ms 2388 KB Output is correct
43 Incorrect 30 ms 3228 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 292 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 52 ms 5200 KB Output is correct
28 Correct 94 ms 8328 KB Output is correct
29 Correct 66 ms 6992 KB Output is correct
30 Correct 43 ms 4980 KB Output is correct
31 Correct 59 ms 6656 KB Output is correct
32 Correct 45 ms 4244 KB Output is correct
33 Correct 61 ms 6732 KB Output is correct
34 Correct 67 ms 5548 KB Output is correct
35 Correct 60 ms 6260 KB Output is correct
36 Correct 50 ms 5928 KB Output is correct
37 Correct 55 ms 6272 KB Output is correct
38 Correct 53 ms 6324 KB Output is correct
39 Correct 59 ms 6732 KB Output is correct
40 Correct 51 ms 5892 KB Output is correct
41 Correct 52 ms 6020 KB Output is correct
42 Correct 18 ms 2388 KB Output is correct
43 Incorrect 30 ms 3228 KB Output isn't correct
44 Halted 0 ms 0 KB -