답안 #576894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576894 2022-06-13T17:51:38 Z wiwiho Uplifting Excursion (BOI22_vault) C++14
20 / 100
2929 ms 15936 KB
#include <bits/stdc++.h>

#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(iter(a), greater<>())
#define eb emplace_back
#define pob pop_back()
#define ef emplace_front
#define pof pop_front()
#define mp make_pair
#define F first
#define S second
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) { \
    for(auto pv : a) b << setw(4) << pv << " "; \
    b << "\n"; \
}

using namespace std;

typedef long long ll;

using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll MAX = 1LL << 60;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int M, L;
    cin >> M >> L;
    assert(M <= 100);

    vector<ll> cnt(2 * M + 1);
    ll mx = 0, mn = 0;
    for(int i = 0; i <= 2 * M; i++){
        cin >> cnt[i];
        assert(cnt[i] <= 100);
        if(i - M > 0) mx += (i - M) * cnt[i];
        if(i - M < 0) mn += (i - M) * cnt[i];
    }
    //cerr << "ok\n";

    if(L < mn || mx < L){
        cout << "impossible\n";
        return 0;
    }

    ll total = mx - mn + 1;
    vector<ll> dp(total + 1, -1);
    dp[-mn] = cnt[M];

    //cerr << "test " << 0 << "  ";
    //printv(dp, cerr);
    
    for(int i = 0; i < M; i++){
        int t = -(i - M);
        auto calc = [&](int x){
            return dp[x] + x / t;
        };
        vector<deque<pll>> dq(t);
        for(int j = total - 1; j >= 0; j--){
            int id = j % t;
            while(!dq[id].empty() && dq[id].front().F / t > j / t + cnt[i]) dq[id].pof;
            while(!dq[id].empty() && dq[id].back().S <= calc(j)) dq[id].pob;
            if(dp[j] != -1){
                //cerr << "push " << j << " " << calc(j) << "\n";
                dq[id].eb(mp(j, calc(j)));
            }
            if(dq[id].empty()) continue;
            dp[j] = dq[id].front().S - j / t;
        }
        //cerr << "test " << -t << "  ";
        //printv(dp, cerr);
    }

    vector<ll> dp2(total, -MAX);

    for(int i = M + 1; i <= 2 * M; i++){
        int t = i - M;
        auto calc = [&](int x){
            return dp[x] - x / t;
        };
        vector<deque<pii>> dq(t);
        for(int j = 0; j < total; j++){
            int id = j % t;
            while(!dq[id].empty() && dq[id].front().F / t < j / t - cnt[i]) dq[id].pof;
            while(!dq[id].empty() && dq[id].back().S <= calc(j)) dq[id].pob;
            if(dp[j] != -1){
                //cerr << "push " << j << " " << calc(j) << "\n";
                dq[id].eb(mp(j, calc(j)));
            }
            if(dq[id].empty()) continue;
            dp[j] = dq[id].front().S + j / t;
        }
        //cerr << "test " << t << "  ";
        //printv(dp, cerr);
    }

    if(dp[-mn + L] < 0) cout << "impossible\n";
    else cout << dp[-mn + L] << "\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 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 96 ms 1396 KB Output is correct
7 Correct 36 ms 944 KB Output is correct
8 Correct 91 ms 1384 KB Output is correct
9 Correct 178 ms 2208 KB Output is correct
10 Correct 3 ms 388 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 96 ms 1396 KB Output is correct
7 Correct 36 ms 944 KB Output is correct
8 Correct 91 ms 1384 KB Output is correct
9 Correct 178 ms 2208 KB Output is correct
10 Correct 3 ms 388 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 103 ms 1420 KB Output is correct
18 Correct 40 ms 716 KB Output is correct
19 Correct 89 ms 1348 KB Output is correct
20 Correct 172 ms 2260 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1468 ms 8404 KB Output is correct
25 Correct 566 ms 3836 KB Output is correct
26 Correct 2921 ms 15904 KB Output is correct
27 Correct 2929 ms 15936 KB Output is correct
28 Correct 27 ms 688 KB Output is correct
29 Correct 23 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 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 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 96 ms 1396 KB Output is correct
7 Correct 36 ms 944 KB Output is correct
8 Correct 91 ms 1384 KB Output is correct
9 Correct 178 ms 2208 KB Output is correct
10 Correct 3 ms 388 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 1 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 1 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 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 96 ms 1396 KB Output is correct
7 Correct 36 ms 944 KB Output is correct
8 Correct 91 ms 1384 KB Output is correct
9 Correct 178 ms 2208 KB Output is correct
10 Correct 3 ms 388 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 103 ms 1420 KB Output is correct
18 Correct 40 ms 716 KB Output is correct
19 Correct 89 ms 1348 KB Output is correct
20 Correct 172 ms 2260 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1468 ms 8404 KB Output is correct
25 Correct 566 ms 3836 KB Output is correct
26 Correct 2921 ms 15904 KB Output is correct
27 Correct 2929 ms 15936 KB Output is correct
28 Correct 27 ms 688 KB Output is correct
29 Correct 23 ms 596 KB Output is correct
30 Correct 1 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 1 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 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 96 ms 1396 KB Output is correct
7 Correct 36 ms 944 KB Output is correct
8 Correct 91 ms 1384 KB Output is correct
9 Correct 178 ms 2208 KB Output is correct
10 Correct 3 ms 388 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 103 ms 1420 KB Output is correct
18 Correct 40 ms 716 KB Output is correct
19 Correct 89 ms 1348 KB Output is correct
20 Correct 172 ms 2260 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1468 ms 8404 KB Output is correct
25 Correct 566 ms 3836 KB Output is correct
26 Correct 2921 ms 15904 KB Output is correct
27 Correct 2929 ms 15936 KB Output is correct
28 Correct 27 ms 688 KB Output is correct
29 Correct 23 ms 596 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -