답안 #680283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680283 2023-01-10T13:03:00 Z mjhmjh1104 Tortoise (CEOI21_tortoise) C++17
48 / 100
3000 ms 224540 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> mem;

int f(int x, int y, int z, int w) {
    if (y > 2 * n - 2) return 0;
    if (mem.find({ x, y, z, w }) != mem.end()) return mem[{ x, y, z, w }];
    if (w && a[x] == -1) return f(x, y, z, 0);
    int res = 0;
    if (w && a[x] != -1) res = max(res, f(x + 1, y - 1, min(n, max(a[x + 1], 0)), 1));
    if (x < n - 1) res = max(res, f(x + 1, y + 1, min(n, max(a[x + 1], 0)), 0));
    if (pv[x] != -1 && z > 0 && y <= 2 * x) {
        int dist = x - pv[x];
        res = max(res, f(x, y + 2 * dist, z - 1, 0) + 1);
    }
    if (nx[x] != -1 && z > 0 && y <= 2 * x) {
        int dist = nx[x] - x;
        res = max(res, f(x, y + 2 * dist, z - 1, 1) + 1);
    }
    return mem[{ x, y, z, w }] = 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));
}

Compilation message

tortoise.cpp: In function 'int main()':
tortoise.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
tortoise.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%d", a + i);
      |         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 19 ms 2768 KB Output is correct
28 Correct 33 ms 4200 KB Output is correct
29 Correct 30 ms 3696 KB Output is correct
30 Correct 19 ms 2636 KB Output is correct
31 Correct 25 ms 3400 KB Output is correct
32 Correct 15 ms 2260 KB Output is correct
33 Correct 29 ms 3492 KB Output is correct
34 Correct 20 ms 2848 KB Output is correct
35 Correct 22 ms 3272 KB Output is correct
36 Correct 20 ms 3156 KB Output is correct
37 Correct 24 ms 3312 KB Output is correct
38 Correct 22 ms 3300 KB Output is correct
39 Correct 23 ms 3540 KB Output is correct
40 Correct 21 ms 3076 KB Output is correct
41 Correct 22 ms 3120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 19 ms 2768 KB Output is correct
28 Correct 33 ms 4200 KB Output is correct
29 Correct 30 ms 3696 KB Output is correct
30 Correct 19 ms 2636 KB Output is correct
31 Correct 25 ms 3400 KB Output is correct
32 Correct 15 ms 2260 KB Output is correct
33 Correct 29 ms 3492 KB Output is correct
34 Correct 20 ms 2848 KB Output is correct
35 Correct 22 ms 3272 KB Output is correct
36 Correct 20 ms 3156 KB Output is correct
37 Correct 24 ms 3312 KB Output is correct
38 Correct 22 ms 3300 KB Output is correct
39 Correct 23 ms 3540 KB Output is correct
40 Correct 21 ms 3076 KB Output is correct
41 Correct 22 ms 3120 KB Output is correct
42 Correct 9 ms 1492 KB Output is correct
43 Correct 14 ms 1876 KB Output is correct
44 Correct 19 ms 2568 KB Output is correct
45 Correct 24 ms 3220 KB Output is correct
46 Correct 10 ms 1812 KB Output is correct
47 Correct 15 ms 2204 KB Output is correct
48 Correct 36 ms 4428 KB Output is correct
49 Correct 23 ms 2948 KB Output is correct
50 Correct 194 ms 16160 KB Output is correct
51 Correct 215 ms 16672 KB Output is correct
52 Correct 98 ms 8176 KB Output is correct
53 Correct 313 ms 26276 KB Output is correct
54 Correct 535 ms 40512 KB Output is correct
55 Correct 169 ms 15640 KB Output is correct
56 Correct 3 ms 596 KB Output is correct
57 Correct 40 ms 3928 KB Output is correct
58 Correct 61 ms 6392 KB Output is correct
59 Correct 48 ms 4724 KB Output is correct
60 Correct 138 ms 12240 KB Output is correct
61 Correct 34 ms 4360 KB Output is correct
62 Correct 74 ms 7204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 19 ms 2768 KB Output is correct
28 Correct 33 ms 4200 KB Output is correct
29 Correct 30 ms 3696 KB Output is correct
30 Correct 19 ms 2636 KB Output is correct
31 Correct 25 ms 3400 KB Output is correct
32 Correct 15 ms 2260 KB Output is correct
33 Correct 29 ms 3492 KB Output is correct
34 Correct 20 ms 2848 KB Output is correct
35 Correct 22 ms 3272 KB Output is correct
36 Correct 20 ms 3156 KB Output is correct
37 Correct 24 ms 3312 KB Output is correct
38 Correct 22 ms 3300 KB Output is correct
39 Correct 23 ms 3540 KB Output is correct
40 Correct 21 ms 3076 KB Output is correct
41 Correct 22 ms 3120 KB Output is correct
42 Correct 9 ms 1492 KB Output is correct
43 Correct 14 ms 1876 KB Output is correct
44 Correct 19 ms 2568 KB Output is correct
45 Correct 24 ms 3220 KB Output is correct
46 Correct 10 ms 1812 KB Output is correct
47 Correct 15 ms 2204 KB Output is correct
48 Correct 36 ms 4428 KB Output is correct
49 Correct 23 ms 2948 KB Output is correct
50 Correct 194 ms 16160 KB Output is correct
51 Correct 215 ms 16672 KB Output is correct
52 Correct 98 ms 8176 KB Output is correct
53 Correct 313 ms 26276 KB Output is correct
54 Correct 535 ms 40512 KB Output is correct
55 Correct 169 ms 15640 KB Output is correct
56 Correct 3 ms 596 KB Output is correct
57 Correct 40 ms 3928 KB Output is correct
58 Correct 61 ms 6392 KB Output is correct
59 Correct 48 ms 4724 KB Output is correct
60 Correct 138 ms 12240 KB Output is correct
61 Correct 34 ms 4360 KB Output is correct
62 Correct 74 ms 7204 KB Output is correct
63 Execution timed out 3085 ms 224540 KB Time limit exceeded
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 19 ms 2768 KB Output is correct
28 Correct 33 ms 4200 KB Output is correct
29 Correct 30 ms 3696 KB Output is correct
30 Correct 19 ms 2636 KB Output is correct
31 Correct 25 ms 3400 KB Output is correct
32 Correct 15 ms 2260 KB Output is correct
33 Correct 29 ms 3492 KB Output is correct
34 Correct 20 ms 2848 KB Output is correct
35 Correct 22 ms 3272 KB Output is correct
36 Correct 20 ms 3156 KB Output is correct
37 Correct 24 ms 3312 KB Output is correct
38 Correct 22 ms 3300 KB Output is correct
39 Correct 23 ms 3540 KB Output is correct
40 Correct 21 ms 3076 KB Output is correct
41 Correct 22 ms 3120 KB Output is correct
42 Correct 9 ms 1492 KB Output is correct
43 Correct 14 ms 1876 KB Output is correct
44 Correct 19 ms 2568 KB Output is correct
45 Correct 24 ms 3220 KB Output is correct
46 Correct 10 ms 1812 KB Output is correct
47 Correct 15 ms 2204 KB Output is correct
48 Correct 36 ms 4428 KB Output is correct
49 Correct 23 ms 2948 KB Output is correct
50 Correct 194 ms 16160 KB Output is correct
51 Correct 215 ms 16672 KB Output is correct
52 Correct 98 ms 8176 KB Output is correct
53 Correct 313 ms 26276 KB Output is correct
54 Correct 535 ms 40512 KB Output is correct
55 Correct 169 ms 15640 KB Output is correct
56 Correct 3 ms 596 KB Output is correct
57 Correct 40 ms 3928 KB Output is correct
58 Correct 61 ms 6392 KB Output is correct
59 Correct 48 ms 4724 KB Output is correct
60 Correct 138 ms 12240 KB Output is correct
61 Correct 34 ms 4360 KB Output is correct
62 Correct 74 ms 7204 KB Output is correct
63 Execution timed out 3085 ms 224540 KB Time limit exceeded
64 Halted 0 ms 0 KB -