Submission #577114

# Submission time Handle Problem Language Result Execution time Memory
577114 2022-06-14T06:14:43 Z tengiz05 Tortoise (CEOI21_tortoise) C++17
18 / 100
238 ms 220220 KB
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void chmax(int &a, int 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) {
            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<int>(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];
                    for (int y : {l[x], r[x]}) {
                        if (y == 0 || y == n + 1)
                            continue;
                        if (1 + (i + abs(x - j) + 1) / 2 <= x) {
                            chmax(dp[min(2 * n, i + abs(x - j) + abs(x - y))][y][p + 1], dp[i][j][k] + 1);
                        }
                    }
                }
            }
        }
    }
    
    int 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]);
            }
        }
    }
    
    cout << b.size() - 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 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 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 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 0 ms 340 KB Output is correct
24 Correct 1 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 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 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 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 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 0 ms 340 KB Output is correct
24 Correct 1 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 138 ms 126520 KB Output is correct
28 Correct 212 ms 203268 KB Output is correct
29 Correct 182 ms 176968 KB Output is correct
30 Correct 132 ms 136772 KB Output is correct
31 Correct 202 ms 208716 KB Output is correct
32 Correct 85 ms 82840 KB Output is correct
33 Correct 161 ms 169620 KB Output is correct
34 Correct 125 ms 136728 KB Output is correct
35 Correct 214 ms 220064 KB Output is correct
36 Correct 197 ms 220160 KB Output is correct
37 Correct 238 ms 220176 KB Output is correct
38 Correct 226 ms 220108 KB Output is correct
39 Correct 212 ms 220068 KB Output is correct
40 Correct 206 ms 220220 KB Output is correct
41 Correct 196 ms 220168 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 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 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 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 0 ms 340 KB Output is correct
24 Correct 1 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 138 ms 126520 KB Output is correct
28 Correct 212 ms 203268 KB Output is correct
29 Correct 182 ms 176968 KB Output is correct
30 Correct 132 ms 136772 KB Output is correct
31 Correct 202 ms 208716 KB Output is correct
32 Correct 85 ms 82840 KB Output is correct
33 Correct 161 ms 169620 KB Output is correct
34 Correct 125 ms 136728 KB Output is correct
35 Correct 214 ms 220064 KB Output is correct
36 Correct 197 ms 220160 KB Output is correct
37 Correct 238 ms 220176 KB Output is correct
38 Correct 226 ms 220108 KB Output is correct
39 Correct 212 ms 220068 KB Output is correct
40 Correct 206 ms 220220 KB Output is correct
41 Correct 196 ms 220168 KB Output is correct
42 Incorrect 55 ms 70028 KB Output isn't correct
43 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 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 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 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 0 ms 340 KB Output is correct
24 Correct 1 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 138 ms 126520 KB Output is correct
28 Correct 212 ms 203268 KB Output is correct
29 Correct 182 ms 176968 KB Output is correct
30 Correct 132 ms 136772 KB Output is correct
31 Correct 202 ms 208716 KB Output is correct
32 Correct 85 ms 82840 KB Output is correct
33 Correct 161 ms 169620 KB Output is correct
34 Correct 125 ms 136728 KB Output is correct
35 Correct 214 ms 220064 KB Output is correct
36 Correct 197 ms 220160 KB Output is correct
37 Correct 238 ms 220176 KB Output is correct
38 Correct 226 ms 220108 KB Output is correct
39 Correct 212 ms 220068 KB Output is correct
40 Correct 206 ms 220220 KB Output is correct
41 Correct 196 ms 220168 KB Output is correct
42 Incorrect 55 ms 70028 KB Output isn't correct
43 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 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 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 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 0 ms 340 KB Output is correct
24 Correct 1 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 138 ms 126520 KB Output is correct
28 Correct 212 ms 203268 KB Output is correct
29 Correct 182 ms 176968 KB Output is correct
30 Correct 132 ms 136772 KB Output is correct
31 Correct 202 ms 208716 KB Output is correct
32 Correct 85 ms 82840 KB Output is correct
33 Correct 161 ms 169620 KB Output is correct
34 Correct 125 ms 136728 KB Output is correct
35 Correct 214 ms 220064 KB Output is correct
36 Correct 197 ms 220160 KB Output is correct
37 Correct 238 ms 220176 KB Output is correct
38 Correct 226 ms 220108 KB Output is correct
39 Correct 212 ms 220068 KB Output is correct
40 Correct 206 ms 220220 KB Output is correct
41 Correct 196 ms 220168 KB Output is correct
42 Incorrect 55 ms 70028 KB Output isn't correct
43 Halted 0 ms 0 KB -