Submission #527769

# Submission time Handle Problem Language Result Execution time Memory
527769 2022-02-18T08:59:54 Z KoD Cigle (COI21_cigle) C++17
100 / 100
513 ms 294728 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

constexpr int M = 5000;
constexpr int inf = (1ll << 30) - 1;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;
    std::cin >> N;
    vector<int> D(N + 1);
    for (int i = 0; i < N; ++i) {
        std::cin >> D[i + 1];
        D[i + 1] += D[i];
    }
    vector score(N + 1, vector(N + 1, 0));
    for (int m = 0; m <= N; ++m) {
        for (int l = m - 1, r = m, s = 0; l >= 0; --l) {
            while (r <= N and D[m] - D[l] > D[r] - D[m]) {
                r += 1;
            }
            if (r <= N) {
                score[m][l] = s;
                s += (D[m] - D[l] == D[r] - D[m]);
            }
        }
        for (int r = m + 1, l = m, s = 0; r <= N; ++r) {
            while (l >= 0 and D[r] - D[m] > D[m] - D[l]) {
                l -= 1;
            }
            if (l >= 0) {
                score[m][r] = s;
                s += (D[m] - D[l] == D[r] - D[m]);
            }
        }
    }
    vector dp(N + 1, vector(N + 1, -inf));
    vector max(N + 1, vector(N + 1, -inf));
    for (int j = 1; j <= N; ++j) {
        dp[0][j] = 0;
    } 
    for (int i = 0; i <= N; ++i) {
        int l = i, r = i;
        for (int j = i; j <= N; ++j) {
            
            if (i > 0) {
                max[i][j] = std::max(max[i][j], max[i - 1][j]);
            }
            
            // l, i -> i, j
            // D[i] - D[j] <= D[i] - D[l]
            // dp[l][i] + score[i][j]
            while (l >= 0 and D[j] - D[i] > D[i] - D[l]) {
                l -= 1;
            }
            if (l >= 0) {
                dp[i][j] = std::max(dp[i][j], max[l][i] + score[i][j]);
            }

            if (j > 0) {
                dp[i][j] = std::max(dp[i][j], dp[i][j - 1]);
            }

            max[i][j] = std::max(max[i][j], dp[i][j]);

            // i, j -> j, r
            // D[j] - D[i] <= D[r] - D[j]
            // dp[i][j] + score[j][i]
            while (r <= N and D[j] - D[i] > D[r] - D[j]) {
                r += 1;
            }
            if (r <= N) {
                dp[j][r] = std::max(dp[j][r], dp[i][j] + score[j][i]);
            }

        }
    }
    int ans = 0;
    for (const auto& v : dp) {
        for (const auto& x : v) {
            ans = std::max(ans, x);
        }
    }
    std::cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3276 KB Output is correct
2 Correct 3 ms 3276 KB Output is correct
3 Correct 4 ms 3256 KB Output is correct
4 Correct 3 ms 3276 KB Output is correct
5 Correct 3 ms 3276 KB Output is correct
6 Correct 5 ms 3248 KB Output is correct
7 Correct 4 ms 3276 KB Output is correct
8 Correct 4 ms 3276 KB Output is correct
9 Correct 6 ms 3276 KB Output is correct
10 Correct 5 ms 3276 KB Output is correct
11 Correct 4 ms 3276 KB Output is correct
12 Correct 4 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 3 ms 3276 KB Output is correct
22 Correct 3 ms 3276 KB Output is correct
23 Correct 4 ms 3256 KB Output is correct
24 Correct 3 ms 3276 KB Output is correct
25 Correct 3 ms 3276 KB Output is correct
26 Correct 5 ms 3248 KB Output is correct
27 Correct 4 ms 3276 KB Output is correct
28 Correct 4 ms 3276 KB Output is correct
29 Correct 6 ms 3276 KB Output is correct
30 Correct 5 ms 3276 KB Output is correct
31 Correct 4 ms 3276 KB Output is correct
32 Correct 4 ms 3276 KB Output is correct
33 Correct 3 ms 3252 KB Output is correct
34 Correct 3 ms 3276 KB Output is correct
35 Correct 4 ms 3276 KB Output is correct
36 Correct 3 ms 3276 KB Output is correct
37 Correct 4 ms 3276 KB Output is correct
38 Correct 4 ms 3276 KB Output is correct
39 Correct 5 ms 3276 KB Output is correct
40 Correct 5 ms 3276 KB Output is correct
41 Correct 4 ms 3256 KB Output is correct
42 Correct 4 ms 3276 KB Output is correct
43 Correct 4 ms 3308 KB Output is correct
44 Correct 5 ms 3256 KB Output is correct
45 Correct 4 ms 3276 KB Output is correct
46 Correct 4 ms 3276 KB Output is correct
47 Correct 4 ms 3276 KB Output is correct
48 Correct 4 ms 3252 KB Output is correct
49 Correct 4 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 3 ms 3276 KB Output is correct
22 Correct 3 ms 3276 KB Output is correct
23 Correct 4 ms 3256 KB Output is correct
24 Correct 3 ms 3276 KB Output is correct
25 Correct 3 ms 3276 KB Output is correct
26 Correct 5 ms 3248 KB Output is correct
27 Correct 4 ms 3276 KB Output is correct
28 Correct 4 ms 3276 KB Output is correct
29 Correct 6 ms 3276 KB Output is correct
30 Correct 5 ms 3276 KB Output is correct
31 Correct 4 ms 3276 KB Output is correct
32 Correct 4 ms 3276 KB Output is correct
33 Correct 3 ms 3252 KB Output is correct
34 Correct 3 ms 3276 KB Output is correct
35 Correct 4 ms 3276 KB Output is correct
36 Correct 3 ms 3276 KB Output is correct
37 Correct 4 ms 3276 KB Output is correct
38 Correct 4 ms 3276 KB Output is correct
39 Correct 5 ms 3276 KB Output is correct
40 Correct 5 ms 3276 KB Output is correct
41 Correct 4 ms 3256 KB Output is correct
42 Correct 4 ms 3276 KB Output is correct
43 Correct 4 ms 3308 KB Output is correct
44 Correct 5 ms 3256 KB Output is correct
45 Correct 4 ms 3276 KB Output is correct
46 Correct 4 ms 3276 KB Output is correct
47 Correct 4 ms 3276 KB Output is correct
48 Correct 4 ms 3252 KB Output is correct
49 Correct 4 ms 3276 KB Output is correct
50 Correct 447 ms 294528 KB Output is correct
51 Correct 386 ms 294700 KB Output is correct
52 Correct 385 ms 294500 KB Output is correct
53 Correct 390 ms 294568 KB Output is correct
54 Correct 434 ms 294468 KB Output is correct
55 Correct 394 ms 294728 KB Output is correct
56 Correct 431 ms 294596 KB Output is correct
57 Correct 451 ms 294528 KB Output is correct
58 Correct 513 ms 294628 KB Output is correct
59 Correct 484 ms 294596 KB Output is correct
60 Correct 508 ms 294468 KB Output is correct
61 Correct 450 ms 294596 KB Output is correct
62 Correct 439 ms 294468 KB Output is correct
63 Correct 418 ms 294456 KB Output is correct
64 Correct 419 ms 294460 KB Output is correct
65 Correct 421 ms 294540 KB Output is correct
66 Correct 461 ms 294632 KB Output is correct
67 Correct 426 ms 294468 KB Output is correct
68 Correct 411 ms 294544 KB Output is correct
69 Correct 399 ms 294524 KB Output is correct
70 Correct 475 ms 294636 KB Output is correct
71 Correct 506 ms 294460 KB Output is correct
72 Correct 500 ms 294540 KB Output is correct