답안 #581236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581236 2022-06-22T12:08:45 Z KoD Uplifting Excursion (BOI22_vault) C++17
0 / 100
20 ms 1172 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) {
                std::deque<pair<int, int>> deq;
                for (int q = 0;; ++q) {
                    const int i = r + q * w;
                    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.empty() and deq.front().second + K < q) {
                        deq.pop_front();
                    }
                    if (!deq.empty()) {
                        next[i] = deq.back().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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 11 ms 812 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 14 ms 736 KB Output is correct
9 Correct 20 ms 1172 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 11 ms 812 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 14 ms 736 KB Output is correct
9 Correct 20 ms 1172 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 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 1 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 1 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 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 11 ms 812 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 14 ms 736 KB Output is correct
9 Correct 20 ms 1172 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 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 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 11 ms 812 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 14 ms 736 KB Output is correct
9 Correct 20 ms 1172 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 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 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 11 ms 812 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 14 ms 736 KB Output is correct
9 Correct 20 ms 1172 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -