Submission #576821

# Submission time Handle Problem Language Result Execution time Memory
576821 2022-06-13T15:02:34 Z Lucpp Uplifting Excursion (BOI22_vault) C++14
50 / 100
4520 ms 8272 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MAX = 50*100*101;
const ll INF = 1e18;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll M, L;
    cin >> M >> L;
    vector<ll> a(2*M+1);
    for(int i = 0; i < 2*M+1; ++i) cin >> a[i];
    vector<ll> dp(2*MAX+1, -INF);
    if(L < -MAX){
        cout << "impossible\n";
        return 0;
    }
    dp[MAX] = 0;
    for(int i = 0; i < 2*M+1; ++i){
        if(i == M){
            for(int j = 0; j < 2*MAX+1; ++j) dp[j] += a[M];
            continue;
        }
        int v = (int)(i-M);
        int start = 0;
        if(v < 0) start = (int)(2*MAX+1+v);
        for(int j = start; j < start + abs(v); ++j){
            deque<pair<ll, int>> q;
            for(int k = 0; j+v*k >= 0 && j+v*k < 2*MAX+1; ++k){
                ll x = dp[j+v*k]-k;
                while(!q.empty() && x > q.back().first) q.pop_back();
                q.emplace_back(x, k);
                if(k - q.front().second > min(a[i], M)) q.pop_front();
                dp[j+v*k] = q.front().first + k;
            }
        }
    }
    if(L < 0){
        if(dp[L+MAX] < 0) cout << "impossible\n";
        else cout << dp[L+MAX] << "\n";
        return 0;
    }
    ll ans = -INF;
    if(L <= MAX) ans = dp[MAX+L];
    ll sum = 0;
    ll taken = 0;
    for(int i = 1; i <= M; ++i){
        if(a[M+i] <= M) continue;
        ll take = max(0ll, min(a[M+i]-M, (L-MAX-sum) / i));
        for(; sum+take*i <= L && take <= a[M+i]-M; take++){
            ll nsum = sum+take*i;
            if(L-nsum <= MAX) ans = max(ans, taken+take+dp[MAX+L-nsum]);
        }
        take--;
        sum += take*i;
        taken += take;
    }
    if(ans < 0) cout << "impossible\n";
    else cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 8148 KB Output is correct
2 Correct 42 ms 8148 KB Output is correct
3 Correct 16 ms 8148 KB Output is correct
4 Correct 143 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 822 ms 8232 KB Output is correct
7 Correct 812 ms 8148 KB Output is correct
8 Correct 788 ms 8148 KB Output is correct
9 Correct 848 ms 8148 KB Output is correct
10 Correct 812 ms 8212 KB Output is correct
11 Correct 824 ms 8212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 8148 KB Output is correct
2 Correct 42 ms 8148 KB Output is correct
3 Correct 16 ms 8148 KB Output is correct
4 Correct 143 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 822 ms 8232 KB Output is correct
7 Correct 812 ms 8148 KB Output is correct
8 Correct 788 ms 8148 KB Output is correct
9 Correct 848 ms 8148 KB Output is correct
10 Correct 812 ms 8212 KB Output is correct
11 Correct 824 ms 8212 KB Output is correct
12 Correct 29 ms 8148 KB Output is correct
13 Correct 42 ms 8108 KB Output is correct
14 Correct 18 ms 8152 KB Output is correct
15 Correct 160 ms 8148 KB Output is correct
16 Correct 4 ms 8148 KB Output is correct
17 Correct 832 ms 8232 KB Output is correct
18 Correct 805 ms 8216 KB Output is correct
19 Correct 909 ms 8148 KB Output is correct
20 Correct 845 ms 8148 KB Output is correct
21 Correct 786 ms 8268 KB Output is correct
22 Correct 814 ms 8216 KB Output is correct
23 Correct 1719 ms 8148 KB Output is correct
24 Correct 1690 ms 8228 KB Output is correct
25 Correct 1612 ms 8148 KB Output is correct
26 Correct 1707 ms 8148 KB Output is correct
27 Correct 1646 ms 8148 KB Output is correct
28 Correct 1676 ms 8148 KB Output is correct
29 Correct 1739 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 8148 KB Output is correct
2 Correct 488 ms 8168 KB Output is correct
3 Correct 480 ms 8148 KB Output is correct
4 Correct 498 ms 8148 KB Output is correct
5 Correct 545 ms 8148 KB Output is correct
6 Correct 499 ms 8148 KB Output is correct
7 Correct 454 ms 8148 KB Output is correct
8 Correct 514 ms 8148 KB Output is correct
9 Correct 471 ms 8148 KB Output is correct
10 Correct 476 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 8148 KB Output is correct
2 Correct 488 ms 8168 KB Output is correct
3 Correct 480 ms 8148 KB Output is correct
4 Correct 498 ms 8148 KB Output is correct
5 Correct 545 ms 8148 KB Output is correct
6 Correct 499 ms 8148 KB Output is correct
7 Correct 454 ms 8148 KB Output is correct
8 Correct 514 ms 8148 KB Output is correct
9 Correct 471 ms 8148 KB Output is correct
10 Correct 476 ms 8148 KB Output is correct
11 Correct 38 ms 8148 KB Output is correct
12 Correct 42 ms 8148 KB Output is correct
13 Correct 16 ms 8148 KB Output is correct
14 Correct 145 ms 8148 KB Output is correct
15 Correct 503 ms 8148 KB Output is correct
16 Correct 458 ms 8148 KB Output is correct
17 Correct 484 ms 8148 KB Output is correct
18 Correct 487 ms 8148 KB Output is correct
19 Correct 498 ms 8148 KB Output is correct
20 Correct 488 ms 8148 KB Output is correct
21 Correct 490 ms 8148 KB Output is correct
22 Correct 483 ms 8148 KB Output is correct
23 Correct 483 ms 8148 KB Output is correct
24 Incorrect 473 ms 8148 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 146 ms 8148 KB Output is correct
2 Correct 488 ms 8168 KB Output is correct
3 Correct 480 ms 8148 KB Output is correct
4 Correct 498 ms 8148 KB Output is correct
5 Correct 545 ms 8148 KB Output is correct
6 Correct 499 ms 8148 KB Output is correct
7 Correct 454 ms 8148 KB Output is correct
8 Correct 514 ms 8148 KB Output is correct
9 Correct 471 ms 8148 KB Output is correct
10 Correct 476 ms 8148 KB Output is correct
11 Correct 156 ms 8148 KB Output is correct
12 Correct 491 ms 8180 KB Output is correct
13 Correct 508 ms 8148 KB Output is correct
14 Correct 483 ms 8148 KB Output is correct
15 Correct 466 ms 8148 KB Output is correct
16 Correct 524 ms 8148 KB Output is correct
17 Correct 513 ms 8148 KB Output is correct
18 Correct 501 ms 8148 KB Output is correct
19 Correct 504 ms 8148 KB Output is correct
20 Correct 475 ms 8148 KB Output is correct
21 Correct 868 ms 8216 KB Output is correct
22 Correct 829 ms 8216 KB Output is correct
23 Correct 824 ms 8212 KB Output is correct
24 Correct 827 ms 8216 KB Output is correct
25 Correct 887 ms 8228 KB Output is correct
26 Correct 834 ms 8268 KB Output is correct
27 Correct 844 ms 8216 KB Output is correct
28 Correct 849 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 8148 KB Output is correct
2 Correct 42 ms 8148 KB Output is correct
3 Correct 16 ms 8148 KB Output is correct
4 Correct 143 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 822 ms 8232 KB Output is correct
7 Correct 812 ms 8148 KB Output is correct
8 Correct 788 ms 8148 KB Output is correct
9 Correct 848 ms 8148 KB Output is correct
10 Correct 812 ms 8212 KB Output is correct
11 Correct 824 ms 8212 KB Output is correct
12 Correct 146 ms 8148 KB Output is correct
13 Correct 488 ms 8168 KB Output is correct
14 Correct 480 ms 8148 KB Output is correct
15 Correct 498 ms 8148 KB Output is correct
16 Correct 545 ms 8148 KB Output is correct
17 Correct 499 ms 8148 KB Output is correct
18 Correct 454 ms 8148 KB Output is correct
19 Correct 514 ms 8148 KB Output is correct
20 Correct 471 ms 8148 KB Output is correct
21 Correct 476 ms 8148 KB Output is correct
22 Correct 38 ms 8148 KB Output is correct
23 Correct 42 ms 8148 KB Output is correct
24 Correct 16 ms 8148 KB Output is correct
25 Correct 145 ms 8148 KB Output is correct
26 Correct 503 ms 8148 KB Output is correct
27 Correct 458 ms 8148 KB Output is correct
28 Correct 484 ms 8148 KB Output is correct
29 Correct 487 ms 8148 KB Output is correct
30 Correct 498 ms 8148 KB Output is correct
31 Correct 488 ms 8148 KB Output is correct
32 Correct 490 ms 8148 KB Output is correct
33 Correct 483 ms 8148 KB Output is correct
34 Correct 483 ms 8148 KB Output is correct
35 Incorrect 473 ms 8148 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 146 ms 8148 KB Output is correct
2 Correct 488 ms 8168 KB Output is correct
3 Correct 480 ms 8148 KB Output is correct
4 Correct 498 ms 8148 KB Output is correct
5 Correct 545 ms 8148 KB Output is correct
6 Correct 499 ms 8148 KB Output is correct
7 Correct 454 ms 8148 KB Output is correct
8 Correct 514 ms 8148 KB Output is correct
9 Correct 471 ms 8148 KB Output is correct
10 Correct 476 ms 8148 KB Output is correct
11 Correct 156 ms 8148 KB Output is correct
12 Correct 491 ms 8180 KB Output is correct
13 Correct 508 ms 8148 KB Output is correct
14 Correct 483 ms 8148 KB Output is correct
15 Correct 466 ms 8148 KB Output is correct
16 Correct 524 ms 8148 KB Output is correct
17 Correct 513 ms 8148 KB Output is correct
18 Correct 501 ms 8148 KB Output is correct
19 Correct 504 ms 8148 KB Output is correct
20 Correct 475 ms 8148 KB Output is correct
21 Correct 868 ms 8216 KB Output is correct
22 Correct 829 ms 8216 KB Output is correct
23 Correct 824 ms 8212 KB Output is correct
24 Correct 827 ms 8216 KB Output is correct
25 Correct 887 ms 8228 KB Output is correct
26 Correct 834 ms 8268 KB Output is correct
27 Correct 844 ms 8216 KB Output is correct
28 Correct 849 ms 8148 KB Output is correct
29 Correct 142 ms 8148 KB Output is correct
30 Correct 510 ms 8148 KB Output is correct
31 Correct 475 ms 8148 KB Output is correct
32 Correct 481 ms 8148 KB Output is correct
33 Correct 489 ms 8148 KB Output is correct
34 Correct 483 ms 8132 KB Output is correct
35 Correct 474 ms 8148 KB Output is correct
36 Correct 492 ms 8148 KB Output is correct
37 Correct 473 ms 8148 KB Output is correct
38 Correct 501 ms 8148 KB Output is correct
39 Correct 819 ms 8216 KB Output is correct
40 Correct 868 ms 8216 KB Output is correct
41 Correct 820 ms 8216 KB Output is correct
42 Correct 843 ms 8228 KB Output is correct
43 Correct 823 ms 8216 KB Output is correct
44 Correct 870 ms 8212 KB Output is correct
45 Correct 858 ms 8212 KB Output is correct
46 Correct 800 ms 8216 KB Output is correct
47 Correct 1647 ms 8148 KB Output is correct
48 Correct 1675 ms 8148 KB Output is correct
49 Correct 1678 ms 8148 KB Output is correct
50 Correct 1683 ms 8148 KB Output is correct
51 Correct 1766 ms 8148 KB Output is correct
52 Correct 1608 ms 8148 KB Output is correct
53 Correct 1614 ms 8148 KB Output is correct
54 Correct 1665 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 8148 KB Output is correct
2 Correct 42 ms 8148 KB Output is correct
3 Correct 16 ms 8148 KB Output is correct
4 Correct 143 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 822 ms 8232 KB Output is correct
7 Correct 812 ms 8148 KB Output is correct
8 Correct 788 ms 8148 KB Output is correct
9 Correct 848 ms 8148 KB Output is correct
10 Correct 812 ms 8212 KB Output is correct
11 Correct 824 ms 8212 KB Output is correct
12 Correct 29 ms 8148 KB Output is correct
13 Correct 42 ms 8108 KB Output is correct
14 Correct 18 ms 8152 KB Output is correct
15 Correct 160 ms 8148 KB Output is correct
16 Correct 4 ms 8148 KB Output is correct
17 Correct 832 ms 8232 KB Output is correct
18 Correct 805 ms 8216 KB Output is correct
19 Correct 909 ms 8148 KB Output is correct
20 Correct 845 ms 8148 KB Output is correct
21 Correct 786 ms 8268 KB Output is correct
22 Correct 814 ms 8216 KB Output is correct
23 Correct 1719 ms 8148 KB Output is correct
24 Correct 1690 ms 8228 KB Output is correct
25 Correct 1612 ms 8148 KB Output is correct
26 Correct 1707 ms 8148 KB Output is correct
27 Correct 1646 ms 8148 KB Output is correct
28 Correct 1676 ms 8148 KB Output is correct
29 Correct 1739 ms 8148 KB Output is correct
30 Correct 146 ms 8148 KB Output is correct
31 Correct 488 ms 8168 KB Output is correct
32 Correct 480 ms 8148 KB Output is correct
33 Correct 498 ms 8148 KB Output is correct
34 Correct 545 ms 8148 KB Output is correct
35 Correct 499 ms 8148 KB Output is correct
36 Correct 454 ms 8148 KB Output is correct
37 Correct 514 ms 8148 KB Output is correct
38 Correct 471 ms 8148 KB Output is correct
39 Correct 476 ms 8148 KB Output is correct
40 Correct 38 ms 8148 KB Output is correct
41 Correct 42 ms 8148 KB Output is correct
42 Correct 16 ms 8148 KB Output is correct
43 Correct 145 ms 8148 KB Output is correct
44 Correct 503 ms 8148 KB Output is correct
45 Correct 458 ms 8148 KB Output is correct
46 Correct 484 ms 8148 KB Output is correct
47 Correct 487 ms 8148 KB Output is correct
48 Correct 498 ms 8148 KB Output is correct
49 Correct 488 ms 8148 KB Output is correct
50 Correct 490 ms 8148 KB Output is correct
51 Correct 483 ms 8148 KB Output is correct
52 Correct 483 ms 8148 KB Output is correct
53 Incorrect 473 ms 8148 KB Output isn't correct
54 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 146 ms 8148 KB Output is correct
2 Correct 488 ms 8168 KB Output is correct
3 Correct 480 ms 8148 KB Output is correct
4 Correct 498 ms 8148 KB Output is correct
5 Correct 545 ms 8148 KB Output is correct
6 Correct 499 ms 8148 KB Output is correct
7 Correct 454 ms 8148 KB Output is correct
8 Correct 514 ms 8148 KB Output is correct
9 Correct 471 ms 8148 KB Output is correct
10 Correct 476 ms 8148 KB Output is correct
11 Correct 156 ms 8148 KB Output is correct
12 Correct 491 ms 8180 KB Output is correct
13 Correct 508 ms 8148 KB Output is correct
14 Correct 483 ms 8148 KB Output is correct
15 Correct 466 ms 8148 KB Output is correct
16 Correct 524 ms 8148 KB Output is correct
17 Correct 513 ms 8148 KB Output is correct
18 Correct 501 ms 8148 KB Output is correct
19 Correct 504 ms 8148 KB Output is correct
20 Correct 475 ms 8148 KB Output is correct
21 Correct 868 ms 8216 KB Output is correct
22 Correct 829 ms 8216 KB Output is correct
23 Correct 824 ms 8212 KB Output is correct
24 Correct 827 ms 8216 KB Output is correct
25 Correct 887 ms 8228 KB Output is correct
26 Correct 834 ms 8268 KB Output is correct
27 Correct 844 ms 8216 KB Output is correct
28 Correct 849 ms 8148 KB Output is correct
29 Correct 142 ms 8148 KB Output is correct
30 Correct 510 ms 8148 KB Output is correct
31 Correct 475 ms 8148 KB Output is correct
32 Correct 481 ms 8148 KB Output is correct
33 Correct 489 ms 8148 KB Output is correct
34 Correct 483 ms 8132 KB Output is correct
35 Correct 474 ms 8148 KB Output is correct
36 Correct 492 ms 8148 KB Output is correct
37 Correct 473 ms 8148 KB Output is correct
38 Correct 501 ms 8148 KB Output is correct
39 Correct 819 ms 8216 KB Output is correct
40 Correct 868 ms 8216 KB Output is correct
41 Correct 820 ms 8216 KB Output is correct
42 Correct 843 ms 8228 KB Output is correct
43 Correct 823 ms 8216 KB Output is correct
44 Correct 870 ms 8212 KB Output is correct
45 Correct 858 ms 8212 KB Output is correct
46 Correct 800 ms 8216 KB Output is correct
47 Correct 1647 ms 8148 KB Output is correct
48 Correct 1675 ms 8148 KB Output is correct
49 Correct 1678 ms 8148 KB Output is correct
50 Correct 1683 ms 8148 KB Output is correct
51 Correct 1766 ms 8148 KB Output is correct
52 Correct 1608 ms 8148 KB Output is correct
53 Correct 1614 ms 8148 KB Output is correct
54 Correct 1665 ms 8148 KB Output is correct
55 Correct 141 ms 8148 KB Output is correct
56 Correct 470 ms 8148 KB Output is correct
57 Correct 474 ms 8148 KB Output is correct
58 Correct 480 ms 8148 KB Output is correct
59 Correct 457 ms 8148 KB Output is correct
60 Correct 488 ms 8148 KB Output is correct
61 Correct 507 ms 8148 KB Output is correct
62 Correct 466 ms 8148 KB Output is correct
63 Correct 490 ms 8148 KB Output is correct
64 Correct 485 ms 8148 KB Output is correct
65 Correct 813 ms 8272 KB Output is correct
66 Correct 804 ms 8208 KB Output is correct
67 Correct 806 ms 8212 KB Output is correct
68 Correct 808 ms 8268 KB Output is correct
69 Correct 813 ms 8220 KB Output is correct
70 Correct 842 ms 8148 KB Output is correct
71 Correct 843 ms 8148 KB Output is correct
72 Correct 807 ms 8148 KB Output is correct
73 Correct 1606 ms 8148 KB Output is correct
74 Correct 1620 ms 8148 KB Output is correct
75 Correct 1655 ms 8148 KB Output is correct
76 Correct 1563 ms 8148 KB Output is correct
77 Correct 1648 ms 8148 KB Output is correct
78 Correct 1623 ms 8148 KB Output is correct
79 Correct 1621 ms 8148 KB Output is correct
80 Correct 1622 ms 8148 KB Output is correct
81 Incorrect 4520 ms 8224 KB Output isn't correct
82 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 8148 KB Output is correct
2 Correct 42 ms 8148 KB Output is correct
3 Correct 16 ms 8148 KB Output is correct
4 Correct 143 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 822 ms 8232 KB Output is correct
7 Correct 812 ms 8148 KB Output is correct
8 Correct 788 ms 8148 KB Output is correct
9 Correct 848 ms 8148 KB Output is correct
10 Correct 812 ms 8212 KB Output is correct
11 Correct 824 ms 8212 KB Output is correct
12 Correct 29 ms 8148 KB Output is correct
13 Correct 42 ms 8108 KB Output is correct
14 Correct 18 ms 8152 KB Output is correct
15 Correct 160 ms 8148 KB Output is correct
16 Correct 4 ms 8148 KB Output is correct
17 Correct 832 ms 8232 KB Output is correct
18 Correct 805 ms 8216 KB Output is correct
19 Correct 909 ms 8148 KB Output is correct
20 Correct 845 ms 8148 KB Output is correct
21 Correct 786 ms 8268 KB Output is correct
22 Correct 814 ms 8216 KB Output is correct
23 Correct 1719 ms 8148 KB Output is correct
24 Correct 1690 ms 8228 KB Output is correct
25 Correct 1612 ms 8148 KB Output is correct
26 Correct 1707 ms 8148 KB Output is correct
27 Correct 1646 ms 8148 KB Output is correct
28 Correct 1676 ms 8148 KB Output is correct
29 Correct 1739 ms 8148 KB Output is correct
30 Correct 146 ms 8148 KB Output is correct
31 Correct 488 ms 8168 KB Output is correct
32 Correct 480 ms 8148 KB Output is correct
33 Correct 498 ms 8148 KB Output is correct
34 Correct 545 ms 8148 KB Output is correct
35 Correct 499 ms 8148 KB Output is correct
36 Correct 454 ms 8148 KB Output is correct
37 Correct 514 ms 8148 KB Output is correct
38 Correct 471 ms 8148 KB Output is correct
39 Correct 476 ms 8148 KB Output is correct
40 Correct 38 ms 8148 KB Output is correct
41 Correct 42 ms 8148 KB Output is correct
42 Correct 16 ms 8148 KB Output is correct
43 Correct 145 ms 8148 KB Output is correct
44 Correct 503 ms 8148 KB Output is correct
45 Correct 458 ms 8148 KB Output is correct
46 Correct 484 ms 8148 KB Output is correct
47 Correct 487 ms 8148 KB Output is correct
48 Correct 498 ms 8148 KB Output is correct
49 Correct 488 ms 8148 KB Output is correct
50 Correct 490 ms 8148 KB Output is correct
51 Correct 483 ms 8148 KB Output is correct
52 Correct 483 ms 8148 KB Output is correct
53 Incorrect 473 ms 8148 KB Output isn't correct
54 Halted 0 ms 0 KB -