답안 #581252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581252 2022-06-22T12:30:07 Z KoD Uplifting Excursion (BOI22_vault) C++17
20 / 100
313 ms 7816 KB
#include <bits/stdc++.h>

using ll = long long;
using std::vector;
using std::array;
using std::tuple;
using std::pair;

template <class F> struct fixed : private F {
    explicit fixed(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args> decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class T>
constexpr T infty = std::numeric_limits<T>::max() / 2;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int M;
    ll T;
    std::cin >> M >> T;
    if (std::abs(T) > 1000000) {
        std::cout << "impossible\n";
        return 0;
    }
    ll zero;
    vector<ll> low(M), high(M);
    for (int i = M - 1; i >= 0; --i) {
        std::cin >> low[i];
    }
    std::cin >> zero;
    for (int i = 0; i < M; ++i) {
        std::cin >> high[i];
    }
    const auto calc = [&](const vector<ll>& vec) {
        vector<int> dp = {0};
        for (int w = 1; w <= M; ++w) {
            const int K = vec[w - 1]; 
            vector<int> next((int)dp.size() + K * w, -infty<int>);
            for (int r = 0; r < w; ++r) {
                if (r >= (int)dp.size()) {
                    break;
                }
                std::deque<pair<int, int>> deq;
                for (int q = 0;; ++q) {
                    const int i = q * w + r;
                    if (i >= (int)next.size()) {
                        break;
                    }
                    if (i < (int)dp.size()) {
                        const int add = dp[i] - q;
                        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();
                    }
                    next[i] = deq.front().first + q;
                }
            }
            dp = std::move(next);
        }
        return dp;
    };
    const auto minus = calc(low);
    const auto plus = calc(high);
    int ans = -infty<int>;
    for (int i = 0; i < (int)minus.size(); ++i) {
        const int j = T + i;
        if (0 <= j and j < (int)plus.size()) {
            ans = std::max(ans, minus[i] + (int)zero + plus[j]);
        }
    }
    if (ans < 0) {
        std::cout << "impossible\n";
    } else {
        std::cout << ans << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 816 KB Output is correct
7 Correct 5 ms 472 KB Output is correct
8 Correct 13 ms 772 KB Output is correct
9 Correct 17 ms 1148 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 816 KB Output is correct
7 Correct 5 ms 472 KB Output is correct
8 Correct 13 ms 772 KB Output is correct
9 Correct 17 ms 1148 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 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 12 ms 780 KB Output is correct
18 Correct 7 ms 468 KB Output is correct
19 Correct 9 ms 688 KB Output is correct
20 Correct 20 ms 1100 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 215 ms 4996 KB Output is correct
25 Correct 54 ms 1808 KB Output is correct
26 Correct 285 ms 7664 KB Output is correct
27 Correct 313 ms 7816 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 816 KB Output is correct
7 Correct 5 ms 472 KB Output is correct
8 Correct 13 ms 772 KB Output is correct
9 Correct 17 ms 1148 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 212 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 816 KB Output is correct
7 Correct 5 ms 472 KB Output is correct
8 Correct 13 ms 772 KB Output is correct
9 Correct 17 ms 1148 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 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 12 ms 780 KB Output is correct
18 Correct 7 ms 468 KB Output is correct
19 Correct 9 ms 688 KB Output is correct
20 Correct 20 ms 1100 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 215 ms 4996 KB Output is correct
25 Correct 54 ms 1808 KB Output is correct
26 Correct 285 ms 7664 KB Output is correct
27 Correct 313 ms 7816 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 816 KB Output is correct
7 Correct 5 ms 472 KB Output is correct
8 Correct 13 ms 772 KB Output is correct
9 Correct 17 ms 1148 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 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 12 ms 780 KB Output is correct
18 Correct 7 ms 468 KB Output is correct
19 Correct 9 ms 688 KB Output is correct
20 Correct 20 ms 1100 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 215 ms 4996 KB Output is correct
25 Correct 54 ms 1808 KB Output is correct
26 Correct 285 ms 7664 KB Output is correct
27 Correct 313 ms 7816 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -