Submission #680281

# Submission time Handle Problem Language Result Execution time Memory
680281 2023-01-10T12:54:48 Z mjhmjh1104 Tortoise (CEOI21_tortoise) C++17
48 / 100
200 ms 444556 KB
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

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

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

int main() {
    memset(dp, -1, sizeof dp);
    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:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
tortoise.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d", a + i);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 162 ms 444504 KB Output is correct
2 Correct 158 ms 444492 KB Output is correct
3 Correct 167 ms 444408 KB Output is correct
4 Correct 158 ms 444372 KB Output is correct
5 Correct 171 ms 444348 KB Output is correct
6 Correct 167 ms 444500 KB Output is correct
7 Correct 188 ms 444364 KB Output is correct
8 Correct 163 ms 444376 KB Output is correct
9 Correct 158 ms 444364 KB Output is correct
10 Correct 164 ms 444404 KB Output is correct
11 Correct 167 ms 444364 KB Output is correct
12 Correct 168 ms 444412 KB Output is correct
13 Correct 167 ms 444388 KB Output is correct
14 Correct 167 ms 444436 KB Output is correct
15 Correct 191 ms 444428 KB Output is correct
16 Correct 169 ms 444360 KB Output is correct
17 Correct 177 ms 444552 KB Output is correct
18 Correct 165 ms 444412 KB Output is correct
19 Correct 176 ms 444360 KB Output is correct
20 Correct 171 ms 444356 KB Output is correct
21 Correct 168 ms 444408 KB Output is correct
22 Correct 168 ms 444364 KB Output is correct
23 Correct 196 ms 444364 KB Output is correct
24 Correct 169 ms 444468 KB Output is correct
25 Correct 168 ms 444440 KB Output is correct
26 Correct 178 ms 444352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 444504 KB Output is correct
2 Correct 158 ms 444492 KB Output is correct
3 Correct 167 ms 444408 KB Output is correct
4 Correct 158 ms 444372 KB Output is correct
5 Correct 171 ms 444348 KB Output is correct
6 Correct 167 ms 444500 KB Output is correct
7 Correct 188 ms 444364 KB Output is correct
8 Correct 163 ms 444376 KB Output is correct
9 Correct 158 ms 444364 KB Output is correct
10 Correct 164 ms 444404 KB Output is correct
11 Correct 167 ms 444364 KB Output is correct
12 Correct 168 ms 444412 KB Output is correct
13 Correct 167 ms 444388 KB Output is correct
14 Correct 167 ms 444436 KB Output is correct
15 Correct 191 ms 444428 KB Output is correct
16 Correct 169 ms 444360 KB Output is correct
17 Correct 177 ms 444552 KB Output is correct
18 Correct 165 ms 444412 KB Output is correct
19 Correct 176 ms 444360 KB Output is correct
20 Correct 171 ms 444356 KB Output is correct
21 Correct 168 ms 444408 KB Output is correct
22 Correct 168 ms 444364 KB Output is correct
23 Correct 196 ms 444364 KB Output is correct
24 Correct 169 ms 444468 KB Output is correct
25 Correct 168 ms 444440 KB Output is correct
26 Correct 178 ms 444352 KB Output is correct
27 Correct 162 ms 444468 KB Output is correct
28 Correct 162 ms 444380 KB Output is correct
29 Correct 165 ms 444400 KB Output is correct
30 Correct 163 ms 444372 KB Output is correct
31 Correct 162 ms 444476 KB Output is correct
32 Correct 167 ms 444440 KB Output is correct
33 Correct 187 ms 444432 KB Output is correct
34 Correct 164 ms 444492 KB Output is correct
35 Correct 168 ms 444492 KB Output is correct
36 Correct 163 ms 444392 KB Output is correct
37 Correct 184 ms 444492 KB Output is correct
38 Correct 178 ms 444484 KB Output is correct
39 Correct 165 ms 444476 KB Output is correct
40 Correct 161 ms 444428 KB Output is correct
41 Correct 159 ms 444484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 444504 KB Output is correct
2 Correct 158 ms 444492 KB Output is correct
3 Correct 167 ms 444408 KB Output is correct
4 Correct 158 ms 444372 KB Output is correct
5 Correct 171 ms 444348 KB Output is correct
6 Correct 167 ms 444500 KB Output is correct
7 Correct 188 ms 444364 KB Output is correct
8 Correct 163 ms 444376 KB Output is correct
9 Correct 158 ms 444364 KB Output is correct
10 Correct 164 ms 444404 KB Output is correct
11 Correct 167 ms 444364 KB Output is correct
12 Correct 168 ms 444412 KB Output is correct
13 Correct 167 ms 444388 KB Output is correct
14 Correct 167 ms 444436 KB Output is correct
15 Correct 191 ms 444428 KB Output is correct
16 Correct 169 ms 444360 KB Output is correct
17 Correct 177 ms 444552 KB Output is correct
18 Correct 165 ms 444412 KB Output is correct
19 Correct 176 ms 444360 KB Output is correct
20 Correct 171 ms 444356 KB Output is correct
21 Correct 168 ms 444408 KB Output is correct
22 Correct 168 ms 444364 KB Output is correct
23 Correct 196 ms 444364 KB Output is correct
24 Correct 169 ms 444468 KB Output is correct
25 Correct 168 ms 444440 KB Output is correct
26 Correct 178 ms 444352 KB Output is correct
27 Correct 162 ms 444468 KB Output is correct
28 Correct 162 ms 444380 KB Output is correct
29 Correct 165 ms 444400 KB Output is correct
30 Correct 163 ms 444372 KB Output is correct
31 Correct 162 ms 444476 KB Output is correct
32 Correct 167 ms 444440 KB Output is correct
33 Correct 187 ms 444432 KB Output is correct
34 Correct 164 ms 444492 KB Output is correct
35 Correct 168 ms 444492 KB Output is correct
36 Correct 163 ms 444392 KB Output is correct
37 Correct 184 ms 444492 KB Output is correct
38 Correct 178 ms 444484 KB Output is correct
39 Correct 165 ms 444476 KB Output is correct
40 Correct 161 ms 444428 KB Output is correct
41 Correct 159 ms 444484 KB Output is correct
42 Correct 187 ms 444436 KB Output is correct
43 Correct 170 ms 444432 KB Output is correct
44 Correct 167 ms 444496 KB Output is correct
45 Correct 170 ms 444416 KB Output is correct
46 Correct 178 ms 444484 KB Output is correct
47 Correct 160 ms 444488 KB Output is correct
48 Correct 174 ms 444556 KB Output is correct
49 Correct 164 ms 444448 KB Output is correct
50 Correct 182 ms 444512 KB Output is correct
51 Correct 178 ms 444480 KB Output is correct
52 Correct 169 ms 444488 KB Output is correct
53 Correct 200 ms 444452 KB Output is correct
54 Correct 183 ms 444512 KB Output is correct
55 Correct 191 ms 444496 KB Output is correct
56 Correct 186 ms 444432 KB Output is correct
57 Correct 168 ms 444476 KB Output is correct
58 Correct 174 ms 444480 KB Output is correct
59 Correct 171 ms 444500 KB Output is correct
60 Correct 169 ms 444500 KB Output is correct
61 Correct 184 ms 444408 KB Output is correct
62 Correct 175 ms 444448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 444504 KB Output is correct
2 Correct 158 ms 444492 KB Output is correct
3 Correct 167 ms 444408 KB Output is correct
4 Correct 158 ms 444372 KB Output is correct
5 Correct 171 ms 444348 KB Output is correct
6 Correct 167 ms 444500 KB Output is correct
7 Correct 188 ms 444364 KB Output is correct
8 Correct 163 ms 444376 KB Output is correct
9 Correct 158 ms 444364 KB Output is correct
10 Correct 164 ms 444404 KB Output is correct
11 Correct 167 ms 444364 KB Output is correct
12 Correct 168 ms 444412 KB Output is correct
13 Correct 167 ms 444388 KB Output is correct
14 Correct 167 ms 444436 KB Output is correct
15 Correct 191 ms 444428 KB Output is correct
16 Correct 169 ms 444360 KB Output is correct
17 Correct 177 ms 444552 KB Output is correct
18 Correct 165 ms 444412 KB Output is correct
19 Correct 176 ms 444360 KB Output is correct
20 Correct 171 ms 444356 KB Output is correct
21 Correct 168 ms 444408 KB Output is correct
22 Correct 168 ms 444364 KB Output is correct
23 Correct 196 ms 444364 KB Output is correct
24 Correct 169 ms 444468 KB Output is correct
25 Correct 168 ms 444440 KB Output is correct
26 Correct 178 ms 444352 KB Output is correct
27 Correct 162 ms 444468 KB Output is correct
28 Correct 162 ms 444380 KB Output is correct
29 Correct 165 ms 444400 KB Output is correct
30 Correct 163 ms 444372 KB Output is correct
31 Correct 162 ms 444476 KB Output is correct
32 Correct 167 ms 444440 KB Output is correct
33 Correct 187 ms 444432 KB Output is correct
34 Correct 164 ms 444492 KB Output is correct
35 Correct 168 ms 444492 KB Output is correct
36 Correct 163 ms 444392 KB Output is correct
37 Correct 184 ms 444492 KB Output is correct
38 Correct 178 ms 444484 KB Output is correct
39 Correct 165 ms 444476 KB Output is correct
40 Correct 161 ms 444428 KB Output is correct
41 Correct 159 ms 444484 KB Output is correct
42 Correct 187 ms 444436 KB Output is correct
43 Correct 170 ms 444432 KB Output is correct
44 Correct 167 ms 444496 KB Output is correct
45 Correct 170 ms 444416 KB Output is correct
46 Correct 178 ms 444484 KB Output is correct
47 Correct 160 ms 444488 KB Output is correct
48 Correct 174 ms 444556 KB Output is correct
49 Correct 164 ms 444448 KB Output is correct
50 Correct 182 ms 444512 KB Output is correct
51 Correct 178 ms 444480 KB Output is correct
52 Correct 169 ms 444488 KB Output is correct
53 Correct 200 ms 444452 KB Output is correct
54 Correct 183 ms 444512 KB Output is correct
55 Correct 191 ms 444496 KB Output is correct
56 Correct 186 ms 444432 KB Output is correct
57 Correct 168 ms 444476 KB Output is correct
58 Correct 174 ms 444480 KB Output is correct
59 Correct 171 ms 444500 KB Output is correct
60 Correct 169 ms 444500 KB Output is correct
61 Correct 184 ms 444408 KB Output is correct
62 Correct 175 ms 444448 KB Output is correct
63 Incorrect 170 ms 444516 KB Output isn't correct
64 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 162 ms 444504 KB Output is correct
2 Correct 158 ms 444492 KB Output is correct
3 Correct 167 ms 444408 KB Output is correct
4 Correct 158 ms 444372 KB Output is correct
5 Correct 171 ms 444348 KB Output is correct
6 Correct 167 ms 444500 KB Output is correct
7 Correct 188 ms 444364 KB Output is correct
8 Correct 163 ms 444376 KB Output is correct
9 Correct 158 ms 444364 KB Output is correct
10 Correct 164 ms 444404 KB Output is correct
11 Correct 167 ms 444364 KB Output is correct
12 Correct 168 ms 444412 KB Output is correct
13 Correct 167 ms 444388 KB Output is correct
14 Correct 167 ms 444436 KB Output is correct
15 Correct 191 ms 444428 KB Output is correct
16 Correct 169 ms 444360 KB Output is correct
17 Correct 177 ms 444552 KB Output is correct
18 Correct 165 ms 444412 KB Output is correct
19 Correct 176 ms 444360 KB Output is correct
20 Correct 171 ms 444356 KB Output is correct
21 Correct 168 ms 444408 KB Output is correct
22 Correct 168 ms 444364 KB Output is correct
23 Correct 196 ms 444364 KB Output is correct
24 Correct 169 ms 444468 KB Output is correct
25 Correct 168 ms 444440 KB Output is correct
26 Correct 178 ms 444352 KB Output is correct
27 Correct 162 ms 444468 KB Output is correct
28 Correct 162 ms 444380 KB Output is correct
29 Correct 165 ms 444400 KB Output is correct
30 Correct 163 ms 444372 KB Output is correct
31 Correct 162 ms 444476 KB Output is correct
32 Correct 167 ms 444440 KB Output is correct
33 Correct 187 ms 444432 KB Output is correct
34 Correct 164 ms 444492 KB Output is correct
35 Correct 168 ms 444492 KB Output is correct
36 Correct 163 ms 444392 KB Output is correct
37 Correct 184 ms 444492 KB Output is correct
38 Correct 178 ms 444484 KB Output is correct
39 Correct 165 ms 444476 KB Output is correct
40 Correct 161 ms 444428 KB Output is correct
41 Correct 159 ms 444484 KB Output is correct
42 Correct 187 ms 444436 KB Output is correct
43 Correct 170 ms 444432 KB Output is correct
44 Correct 167 ms 444496 KB Output is correct
45 Correct 170 ms 444416 KB Output is correct
46 Correct 178 ms 444484 KB Output is correct
47 Correct 160 ms 444488 KB Output is correct
48 Correct 174 ms 444556 KB Output is correct
49 Correct 164 ms 444448 KB Output is correct
50 Correct 182 ms 444512 KB Output is correct
51 Correct 178 ms 444480 KB Output is correct
52 Correct 169 ms 444488 KB Output is correct
53 Correct 200 ms 444452 KB Output is correct
54 Correct 183 ms 444512 KB Output is correct
55 Correct 191 ms 444496 KB Output is correct
56 Correct 186 ms 444432 KB Output is correct
57 Correct 168 ms 444476 KB Output is correct
58 Correct 174 ms 444480 KB Output is correct
59 Correct 171 ms 444500 KB Output is correct
60 Correct 169 ms 444500 KB Output is correct
61 Correct 184 ms 444408 KB Output is correct
62 Correct 175 ms 444448 KB Output is correct
63 Incorrect 170 ms 444516 KB Output isn't correct
64 Halted 0 ms 0 KB -