Submission #577158

# Submission time Handle Problem Language Result Execution time Memory
577158 2022-06-14T08:05:17 Z tengiz05 Tortoise (CEOI21_tortoise) C++17
18 / 100
3000 ms 432940 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;
                chmax(dp[i][j][k + 1], dp[i][j][k]);
                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][k + 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][k + 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 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 161 ms 249748 KB Output is correct
28 Correct 280 ms 399500 KB Output is correct
29 Correct 242 ms 345200 KB Output is correct
30 Correct 186 ms 267996 KB Output is correct
31 Correct 252 ms 407608 KB Output is correct
32 Correct 118 ms 161872 KB Output is correct
33 Correct 237 ms 330700 KB Output is correct
34 Correct 186 ms 268004 KB Output is correct
35 Correct 285 ms 432940 KB Output is correct
36 Correct 261 ms 432940 KB Output is correct
37 Correct 271 ms 432940 KB Output is correct
38 Correct 277 ms 432860 KB Output is correct
39 Correct 282 ms 432940 KB Output is correct
40 Correct 253 ms 432940 KB Output is correct
41 Correct 289 ms 432940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 161 ms 249748 KB Output is correct
28 Correct 280 ms 399500 KB Output is correct
29 Correct 242 ms 345200 KB Output is correct
30 Correct 186 ms 267996 KB Output is correct
31 Correct 252 ms 407608 KB Output is correct
32 Correct 118 ms 161872 KB Output is correct
33 Correct 237 ms 330700 KB Output is correct
34 Correct 186 ms 268004 KB Output is correct
35 Correct 285 ms 432940 KB Output is correct
36 Correct 261 ms 432940 KB Output is correct
37 Correct 271 ms 432940 KB Output is correct
38 Correct 277 ms 432860 KB Output is correct
39 Correct 282 ms 432940 KB Output is correct
40 Correct 253 ms 432940 KB Output is correct
41 Correct 289 ms 432940 KB Output is correct
42 Correct 119 ms 136376 KB Output is correct
43 Correct 102 ms 145848 KB Output is correct
44 Correct 148 ms 217600 KB Output is correct
45 Correct 231 ms 360172 KB Output is correct
46 Correct 149 ms 189952 KB Output is correct
47 Correct 94 ms 133856 KB Output is correct
48 Correct 189 ms 280764 KB Output is correct
49 Correct 135 ms 194828 KB Output is correct
50 Execution timed out 3085 ms 328272 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 161 ms 249748 KB Output is correct
28 Correct 280 ms 399500 KB Output is correct
29 Correct 242 ms 345200 KB Output is correct
30 Correct 186 ms 267996 KB Output is correct
31 Correct 252 ms 407608 KB Output is correct
32 Correct 118 ms 161872 KB Output is correct
33 Correct 237 ms 330700 KB Output is correct
34 Correct 186 ms 268004 KB Output is correct
35 Correct 285 ms 432940 KB Output is correct
36 Correct 261 ms 432940 KB Output is correct
37 Correct 271 ms 432940 KB Output is correct
38 Correct 277 ms 432860 KB Output is correct
39 Correct 282 ms 432940 KB Output is correct
40 Correct 253 ms 432940 KB Output is correct
41 Correct 289 ms 432940 KB Output is correct
42 Correct 119 ms 136376 KB Output is correct
43 Correct 102 ms 145848 KB Output is correct
44 Correct 148 ms 217600 KB Output is correct
45 Correct 231 ms 360172 KB Output is correct
46 Correct 149 ms 189952 KB Output is correct
47 Correct 94 ms 133856 KB Output is correct
48 Correct 189 ms 280764 KB Output is correct
49 Correct 135 ms 194828 KB Output is correct
50 Execution timed out 3085 ms 328272 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 161 ms 249748 KB Output is correct
28 Correct 280 ms 399500 KB Output is correct
29 Correct 242 ms 345200 KB Output is correct
30 Correct 186 ms 267996 KB Output is correct
31 Correct 252 ms 407608 KB Output is correct
32 Correct 118 ms 161872 KB Output is correct
33 Correct 237 ms 330700 KB Output is correct
34 Correct 186 ms 268004 KB Output is correct
35 Correct 285 ms 432940 KB Output is correct
36 Correct 261 ms 432940 KB Output is correct
37 Correct 271 ms 432940 KB Output is correct
38 Correct 277 ms 432860 KB Output is correct
39 Correct 282 ms 432940 KB Output is correct
40 Correct 253 ms 432940 KB Output is correct
41 Correct 289 ms 432940 KB Output is correct
42 Correct 119 ms 136376 KB Output is correct
43 Correct 102 ms 145848 KB Output is correct
44 Correct 148 ms 217600 KB Output is correct
45 Correct 231 ms 360172 KB Output is correct
46 Correct 149 ms 189952 KB Output is correct
47 Correct 94 ms 133856 KB Output is correct
48 Correct 189 ms 280764 KB Output is correct
49 Correct 135 ms 194828 KB Output is correct
50 Execution timed out 3085 ms 328272 KB Time limit exceeded
51 Halted 0 ms 0 KB -