Submission #582860

# Submission time Handle Problem Language Result Execution time Memory
582860 2022-06-24T14:03:05 Z KoD Uplifting Excursion (BOI22_vault) C++17
50 / 100
2097 ms 1356 KB
#include <bits/stdc++.h>

using ll = long long;

using std::vector;
using std::pair;
using std::deque;

constexpr int inf = std::numeric_limits<int>::max() / 2;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int M;
    ll T;
    std::cin >> M >> T;
    vector<ll> A(2 * M + 1);
    ll S = 0;
    for (int i = -M; i <= M; ++i) {
        std::cin >> A[i + M];
        S += i * A[i + M];
    }
    if (S < T) {
        T = -T;
        std::reverse(A.begin(), A.end());
    }
    const int N = M * M;
    vector<int> dp(2 * N + 1, -inf);
    dp[N] = 0;
    const auto update_positive = [&](const ll K, const int W, const int V) {
        for (int r = 0; r < W; ++r) {
            if (r >= (int)dp.size()) {
                break;
            }
            deque<pair<int, int>> deq;
            for (int q = 0;; ++q) {
                const int i = q * W + r;
                if (i >= (int)dp.size()) {
                    break;
                }
                const int add = dp[i] - q * V;
                while (!deq.empty() and deq.back().first < add) {
                    deq.pop_back();
                }
                deq.emplace_back(add, q);
                while (deq.front().second + K < q) {
                    deq.pop_front();
                }
                dp[i] = deq.front().first + q * V;
            }
        }
    };
    const auto update = [&](const ll K, const int W, const int V) {
        if (W > 0) {
            update_positive(K, W, V);
        }
        if (W < 0) {
            std::reverse(dp.begin(), dp.end());
            update_positive(K, -W, V);
            std::reverse(dp.begin(), dp.end());
        }
    };
    S = 0;
    ll sum = 0;
    for (int i = -M; i <= M; ++i) {
        const ll take = i <= 0 ? A[i + M] : std::min(A[i + M], (T - S) / i);
        const ll remain = A[i + M] - take;
        S += i * take;
        sum += take;
        update(take, -i, -1);
        update(remain, i, 1);
    }
    if (std::abs(T - S) > N or dp[T - S + N] < -2 * M) {
        std::cout << "impossible\n";
    } else {
        std::cout << sum + dp[T - S + N] << '\n'; 
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Runtime error 6 ms 468 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Runtime error 6 ms 468 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 324 KB Output is correct
16 Correct 3 ms 212 KB Output is correct
17 Correct 3 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 3 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 3 ms 212 KB Output is correct
22 Correct 3 ms 212 KB Output is correct
23 Correct 3 ms 212 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 3 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 3 ms 212 KB Output is correct
28 Correct 3 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 3 ms 328 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 3 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 3 ms 212 KB Output is correct
19 Correct 3 ms 212 KB Output is correct
20 Correct 3 ms 212 KB Output is correct
21 Correct 10 ms 212 KB Output is correct
22 Correct 11 ms 332 KB Output is correct
23 Correct 10 ms 212 KB Output is correct
24 Correct 10 ms 332 KB Output is correct
25 Correct 11 ms 340 KB Output is correct
26 Correct 10 ms 336 KB Output is correct
27 Correct 10 ms 352 KB Output is correct
28 Correct 10 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Runtime error 6 ms 468 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 3 ms 328 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 3 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 3 ms 212 KB Output is correct
19 Correct 3 ms 212 KB Output is correct
20 Correct 3 ms 212 KB Output is correct
21 Correct 10 ms 212 KB Output is correct
22 Correct 11 ms 332 KB Output is correct
23 Correct 10 ms 212 KB Output is correct
24 Correct 10 ms 332 KB Output is correct
25 Correct 11 ms 340 KB Output is correct
26 Correct 10 ms 336 KB Output is correct
27 Correct 10 ms 352 KB Output is correct
28 Correct 10 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 212 KB Output is correct
31 Correct 3 ms 212 KB Output is correct
32 Correct 2 ms 212 KB Output is correct
33 Correct 4 ms 212 KB Output is correct
34 Correct 3 ms 212 KB Output is correct
35 Correct 3 ms 212 KB Output is correct
36 Correct 3 ms 212 KB Output is correct
37 Correct 3 ms 212 KB Output is correct
38 Correct 2 ms 244 KB Output is correct
39 Correct 10 ms 332 KB Output is correct
40 Correct 10 ms 212 KB Output is correct
41 Correct 11 ms 340 KB Output is correct
42 Correct 10 ms 212 KB Output is correct
43 Correct 10 ms 336 KB Output is correct
44 Correct 11 ms 336 KB Output is correct
45 Correct 10 ms 340 KB Output is correct
46 Correct 10 ms 340 KB Output is correct
47 Correct 76 ms 340 KB Output is correct
48 Correct 81 ms 372 KB Output is correct
49 Correct 80 ms 376 KB Output is correct
50 Correct 75 ms 376 KB Output is correct
51 Correct 78 ms 404 KB Output is correct
52 Correct 77 ms 388 KB Output is correct
53 Correct 81 ms 376 KB Output is correct
54 Correct 80 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Runtime error 6 ms 468 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 3 ms 328 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 3 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 3 ms 212 KB Output is correct
19 Correct 3 ms 212 KB Output is correct
20 Correct 3 ms 212 KB Output is correct
21 Correct 10 ms 212 KB Output is correct
22 Correct 11 ms 332 KB Output is correct
23 Correct 10 ms 212 KB Output is correct
24 Correct 10 ms 332 KB Output is correct
25 Correct 11 ms 340 KB Output is correct
26 Correct 10 ms 336 KB Output is correct
27 Correct 10 ms 352 KB Output is correct
28 Correct 10 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 212 KB Output is correct
31 Correct 3 ms 212 KB Output is correct
32 Correct 2 ms 212 KB Output is correct
33 Correct 4 ms 212 KB Output is correct
34 Correct 3 ms 212 KB Output is correct
35 Correct 3 ms 212 KB Output is correct
36 Correct 3 ms 212 KB Output is correct
37 Correct 3 ms 212 KB Output is correct
38 Correct 2 ms 244 KB Output is correct
39 Correct 10 ms 332 KB Output is correct
40 Correct 10 ms 212 KB Output is correct
41 Correct 11 ms 340 KB Output is correct
42 Correct 10 ms 212 KB Output is correct
43 Correct 10 ms 336 KB Output is correct
44 Correct 11 ms 336 KB Output is correct
45 Correct 10 ms 340 KB Output is correct
46 Correct 10 ms 340 KB Output is correct
47 Correct 76 ms 340 KB Output is correct
48 Correct 81 ms 372 KB Output is correct
49 Correct 80 ms 376 KB Output is correct
50 Correct 75 ms 376 KB Output is correct
51 Correct 78 ms 404 KB Output is correct
52 Correct 77 ms 388 KB Output is correct
53 Correct 81 ms 376 KB Output is correct
54 Correct 80 ms 408 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 2 ms 212 KB Output is correct
57 Correct 3 ms 212 KB Output is correct
58 Correct 3 ms 212 KB Output is correct
59 Correct 3 ms 212 KB Output is correct
60 Correct 3 ms 212 KB Output is correct
61 Correct 3 ms 212 KB Output is correct
62 Correct 3 ms 212 KB Output is correct
63 Correct 3 ms 212 KB Output is correct
64 Correct 3 ms 212 KB Output is correct
65 Correct 10 ms 336 KB Output is correct
66 Correct 11 ms 340 KB Output is correct
67 Correct 11 ms 336 KB Output is correct
68 Correct 10 ms 212 KB Output is correct
69 Correct 11 ms 344 KB Output is correct
70 Correct 10 ms 340 KB Output is correct
71 Correct 10 ms 340 KB Output is correct
72 Correct 10 ms 336 KB Output is correct
73 Correct 74 ms 376 KB Output is correct
74 Correct 76 ms 392 KB Output is correct
75 Correct 81 ms 480 KB Output is correct
76 Correct 81 ms 384 KB Output is correct
77 Correct 77 ms 524 KB Output is correct
78 Correct 75 ms 340 KB Output is correct
79 Correct 76 ms 340 KB Output is correct
80 Correct 80 ms 392 KB Output is correct
81 Correct 2054 ms 1188 KB Output is correct
82 Correct 2081 ms 1032 KB Output is correct
83 Correct 2069 ms 1028 KB Output is correct
84 Correct 2097 ms 1184 KB Output is correct
85 Correct 2067 ms 1016 KB Output is correct
86 Correct 2020 ms 1020 KB Output is correct
87 Correct 2088 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Runtime error 6 ms 468 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -