Submission #577149

# Submission time Handle Problem Language Result Execution time Memory
577149 2022-06-14T07:55:36 Z tengiz05 Tortoise (CEOI21_tortoise) C++17
18 / 100
3000 ms 433044 KB
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void chmax(i64 &a, i64 b) {
    if (a < b)
        a = b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<int> a(n + 1), b, c;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] > 0) {
            for (int j = 1; j <= min(a[i], n); j++) {
                b.push_back(i);
            }
        } else if (a[i] == -1) {
            c.push_back(i);
        }
    }
    
    vector<int> l(n + 1), r(n + 1);
    int lst = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == -1)
            lst = i;
        l[i] = lst;
    }
    lst = n + 1;
    for (int i = n; i >= 1; i--) {
        if (a[i] == -1)
            lst = i;
        r[i] = lst;
    }
    
    vector dp(2 * n + 1, vector(n + 1, vector<i64>(n + 1, -1)));
    
    dp[0][1][0] = 0;
    
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 0; k < int(b.size()); k++) {
                if (dp[i][j][k] == -1)
                    continue;
                for (int p = k; p < int(b.size()); p++) {
                    int x = b[k];
                    if (l[x] != 0) {
                        int y = l[x];
                        if (2 + i + abs(x - j) <= 2 * x) {
                            chmax(dp[min(2 * n, i + abs(x - j) + 2 * abs(x - y))][x][p + 1], dp[i][j][k] + 1);
                        }
                    }
                    if (r[x] != n + 1) {
                        int y = r[x];
                        if (2 + i + abs(x - j) <= 2 * x) {
                            chmax(dp[min(2 * n, i + abs(x - j) + abs(x - y))][y][p + 1], dp[i][j][k] + 1);
                        }
                    }
                }
            }
        }
    }
    
    i64 ans = 0;
    for (int i = 0; i <= 2 * n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 0; k <= int(b.size()); k++) {
                ans = max(ans, dp[i][j][k]);
            }
        }
    }
    i64 sum = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] > 0) {
            sum += a[i];
        }
    }
    
    cout << sum - ans << "\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 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 1 ms 340 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 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 1 ms 340 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 233 ms 249824 KB Output is correct
28 Correct 504 ms 399496 KB Output is correct
29 Correct 305 ms 345200 KB Output is correct
30 Correct 225 ms 268116 KB Output is correct
31 Correct 318 ms 407680 KB Output is correct
32 Correct 140 ms 161736 KB Output is correct
33 Correct 299 ms 330528 KB Output is correct
34 Correct 218 ms 268076 KB Output is correct
35 Correct 345 ms 432936 KB Output is correct
36 Correct 297 ms 432896 KB Output is correct
37 Correct 336 ms 432840 KB Output is correct
38 Correct 305 ms 432888 KB Output is correct
39 Correct 341 ms 432932 KB Output is correct
40 Correct 289 ms 433044 KB Output is correct
41 Correct 297 ms 432880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 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 1 ms 340 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 233 ms 249824 KB Output is correct
28 Correct 504 ms 399496 KB Output is correct
29 Correct 305 ms 345200 KB Output is correct
30 Correct 225 ms 268116 KB Output is correct
31 Correct 318 ms 407680 KB Output is correct
32 Correct 140 ms 161736 KB Output is correct
33 Correct 299 ms 330528 KB Output is correct
34 Correct 218 ms 268076 KB Output is correct
35 Correct 345 ms 432936 KB Output is correct
36 Correct 297 ms 432896 KB Output is correct
37 Correct 336 ms 432840 KB Output is correct
38 Correct 305 ms 432888 KB Output is correct
39 Correct 341 ms 432932 KB Output is correct
40 Correct 289 ms 433044 KB Output is correct
41 Correct 297 ms 432880 KB Output is correct
42 Correct 89 ms 136396 KB Output is correct
43 Correct 123 ms 145868 KB Output is correct
44 Correct 186 ms 217692 KB Output is correct
45 Correct 277 ms 360172 KB Output is correct
46 Correct 113 ms 189900 KB Output is correct
47 Correct 117 ms 133860 KB Output is correct
48 Correct 319 ms 280892 KB Output is correct
49 Correct 198 ms 194940 KB Output is correct
50 Execution timed out 3074 ms 328240 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 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 1 ms 340 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 233 ms 249824 KB Output is correct
28 Correct 504 ms 399496 KB Output is correct
29 Correct 305 ms 345200 KB Output is correct
30 Correct 225 ms 268116 KB Output is correct
31 Correct 318 ms 407680 KB Output is correct
32 Correct 140 ms 161736 KB Output is correct
33 Correct 299 ms 330528 KB Output is correct
34 Correct 218 ms 268076 KB Output is correct
35 Correct 345 ms 432936 KB Output is correct
36 Correct 297 ms 432896 KB Output is correct
37 Correct 336 ms 432840 KB Output is correct
38 Correct 305 ms 432888 KB Output is correct
39 Correct 341 ms 432932 KB Output is correct
40 Correct 289 ms 433044 KB Output is correct
41 Correct 297 ms 432880 KB Output is correct
42 Correct 89 ms 136396 KB Output is correct
43 Correct 123 ms 145868 KB Output is correct
44 Correct 186 ms 217692 KB Output is correct
45 Correct 277 ms 360172 KB Output is correct
46 Correct 113 ms 189900 KB Output is correct
47 Correct 117 ms 133860 KB Output is correct
48 Correct 319 ms 280892 KB Output is correct
49 Correct 198 ms 194940 KB Output is correct
50 Execution timed out 3074 ms 328240 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 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 1 ms 340 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 233 ms 249824 KB Output is correct
28 Correct 504 ms 399496 KB Output is correct
29 Correct 305 ms 345200 KB Output is correct
30 Correct 225 ms 268116 KB Output is correct
31 Correct 318 ms 407680 KB Output is correct
32 Correct 140 ms 161736 KB Output is correct
33 Correct 299 ms 330528 KB Output is correct
34 Correct 218 ms 268076 KB Output is correct
35 Correct 345 ms 432936 KB Output is correct
36 Correct 297 ms 432896 KB Output is correct
37 Correct 336 ms 432840 KB Output is correct
38 Correct 305 ms 432888 KB Output is correct
39 Correct 341 ms 432932 KB Output is correct
40 Correct 289 ms 433044 KB Output is correct
41 Correct 297 ms 432880 KB Output is correct
42 Correct 89 ms 136396 KB Output is correct
43 Correct 123 ms 145868 KB Output is correct
44 Correct 186 ms 217692 KB Output is correct
45 Correct 277 ms 360172 KB Output is correct
46 Correct 113 ms 189900 KB Output is correct
47 Correct 117 ms 133860 KB Output is correct
48 Correct 319 ms 280892 KB Output is correct
49 Correct 198 ms 194940 KB Output is correct
50 Execution timed out 3074 ms 328240 KB Time limit exceeded
51 Halted 0 ms 0 KB -