Submission #577113

# Submission time Handle Problem Language Result Execution time Memory
577113 2022-06-14T06:12:19 Z tengiz05 Tortoise (CEOI21_tortoise) C++17
8 / 100
3000 ms 220128 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 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 : c) {
                        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 0 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 0 ms 276 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 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 1 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 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 1 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 0 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 0 ms 276 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 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 1 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 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 1 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 1209 ms 126632 KB Output is correct
28 Correct 536 ms 203268 KB Output is correct
29 Correct 1294 ms 177024 KB Output is correct
30 Correct 1841 ms 136784 KB Output is correct
31 Correct 2591 ms 208776 KB Output is correct
32 Correct 648 ms 82856 KB Output is correct
33 Correct 993 ms 169624 KB Output is correct
34 Correct 934 ms 136812 KB Output is correct
35 Execution timed out 3099 ms 220128 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 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 0 ms 276 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 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 1 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 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 1 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 1209 ms 126632 KB Output is correct
28 Correct 536 ms 203268 KB Output is correct
29 Correct 1294 ms 177024 KB Output is correct
30 Correct 1841 ms 136784 KB Output is correct
31 Correct 2591 ms 208776 KB Output is correct
32 Correct 648 ms 82856 KB Output is correct
33 Correct 993 ms 169624 KB Output is correct
34 Correct 934 ms 136812 KB Output is correct
35 Execution timed out 3099 ms 220128 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 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 0 ms 276 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 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 1 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 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 1 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 1209 ms 126632 KB Output is correct
28 Correct 536 ms 203268 KB Output is correct
29 Correct 1294 ms 177024 KB Output is correct
30 Correct 1841 ms 136784 KB Output is correct
31 Correct 2591 ms 208776 KB Output is correct
32 Correct 648 ms 82856 KB Output is correct
33 Correct 993 ms 169624 KB Output is correct
34 Correct 934 ms 136812 KB Output is correct
35 Execution timed out 3099 ms 220128 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 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 0 ms 276 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 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 1 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 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 1 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 1209 ms 126632 KB Output is correct
28 Correct 536 ms 203268 KB Output is correct
29 Correct 1294 ms 177024 KB Output is correct
30 Correct 1841 ms 136784 KB Output is correct
31 Correct 2591 ms 208776 KB Output is correct
32 Correct 648 ms 82856 KB Output is correct
33 Correct 993 ms 169624 KB Output is correct
34 Correct 934 ms 136812 KB Output is correct
35 Execution timed out 3099 ms 220128 KB Time limit exceeded
36 Halted 0 ms 0 KB -