답안 #1049848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049848 2024-08-09T05:45:42 Z shiomusubi496 Uplifting Excursion (BOI22_vault) C++17
20 / 100
2408 ms 24052 KB
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)

using namespace std;

using ll = long long;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

using namespace std;

constexpr ll inf = 1e18;

int main() {
    int M; cin >> M;
    ll L; cin >> L;
    vector<ll> A(2 * M + 1);
    rep (i, 2 * M + 1) cin >> A[i];
    if (L < 0) {
        reverse(all(A));
        L = -L;
    }
    ll sml = 0, smr = 0;
    rep (i, 2 * M + 1) {
        if (i < M) sml += A[i] * (i - M);
        if (i > M) smr += A[i] * (i - M);
    }
    if (L < sml || smr < L) {
        puts("impossible");
        return 0;
    }
    vector<pair<int, ll>> B;
    rep (i, 2 * M + 1) {
        if (i == M) continue;
        if (A[i] == 0) continue;
        // if (A[i] > M) continue;
        B.emplace_back(i - M, A[i]);
    }
    vector<ll> dp(smr - sml + 1, -inf);
    dp[0 - sml] = 0;
    for (auto [x, y] : B) {
        int ax = abs(x);
        rep (i, ax) {
            // mod x ごとにスライド最大値の形になる
            vector<ll> memo;
            for (int j = i; j <= smr - sml; j += ax) {
                memo.push_back(dp[j]);
            }
            vector<ll> res(memo.size(), -inf);
            deque<int> st;
            if (x > 0) {
                rep (i, memo.size()) memo[i] -= i;
                rep (i, res.size()) {
                    while (!st.empty() && st.front() < i - y) st.pop_front();
                    while (!st.empty() && memo[st.back()] < memo[i]) st.pop_back();
                    st.push_back(i);
                    res[i] = memo[st.front()] + i;
                }
            }
            else {
                rep (i, memo.size()) memo[i] += i;
                rrep (i, res.size()) {
                    while (!st.empty() && st.front() > i + y) st.pop_front();
                    while (!st.empty() && memo[st.back()] < memo[i]) st.pop_back();
                    st.push_back(i);
                    res[i] = memo[st.front()] - i;
                }
            }
            rep (j, res.size()) dp[j * ax + i] = res[j];
        }
    }
    if (dp[L - sml] >= 0) {
        cout << dp[L - sml] + A[M] << endl;
    }
    else {
        puts("impossible");
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 62 ms 2384 KB Output is correct
7 Correct 10 ms 860 KB Output is correct
8 Correct 59 ms 1964 KB Output is correct
9 Correct 132 ms 3480 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 62 ms 2384 KB Output is correct
7 Correct 10 ms 860 KB Output is correct
8 Correct 59 ms 1964 KB Output is correct
9 Correct 132 ms 3480 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 63 ms 2448 KB Output is correct
18 Correct 10 ms 860 KB Output is correct
19 Correct 57 ms 1908 KB Output is correct
20 Correct 125 ms 3360 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1105 ms 12552 KB Output is correct
25 Correct 150 ms 2512 KB Output is correct
26 Correct 2408 ms 24052 KB Output is correct
27 Correct 2277 ms 23848 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 3 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 3 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 3 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 62 ms 2384 KB Output is correct
7 Correct 10 ms 860 KB Output is correct
8 Correct 59 ms 1964 KB Output is correct
9 Correct 132 ms 3480 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Runtime error 3 ms 604 KB Execution killed with signal 6
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 3 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 62 ms 2384 KB Output is correct
7 Correct 10 ms 860 KB Output is correct
8 Correct 59 ms 1964 KB Output is correct
9 Correct 132 ms 3480 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 63 ms 2448 KB Output is correct
18 Correct 10 ms 860 KB Output is correct
19 Correct 57 ms 1908 KB Output is correct
20 Correct 125 ms 3360 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1105 ms 12552 KB Output is correct
25 Correct 150 ms 2512 KB Output is correct
26 Correct 2408 ms 24052 KB Output is correct
27 Correct 2277 ms 23848 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Runtime error 3 ms 604 KB Execution killed with signal 6
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 3 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 62 ms 2384 KB Output is correct
7 Correct 10 ms 860 KB Output is correct
8 Correct 59 ms 1964 KB Output is correct
9 Correct 132 ms 3480 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 63 ms 2448 KB Output is correct
18 Correct 10 ms 860 KB Output is correct
19 Correct 57 ms 1908 KB Output is correct
20 Correct 125 ms 3360 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1105 ms 12552 KB Output is correct
25 Correct 150 ms 2512 KB Output is correct
26 Correct 2408 ms 24052 KB Output is correct
27 Correct 2277 ms 23848 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Runtime error 3 ms 604 KB Execution killed with signal 6
32 Halted 0 ms 0 KB -