Submission #622346

# Submission time Handle Problem Language Result Execution time Memory
622346 2022-08-04T07:43:13 Z rrrr10000 Uplifting Excursion (BOI22_vault) C++14
45 / 100
1982 ms 13680 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pb emplace_back
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
const ll inf=1001001001001001001;

int main(){
    ll n,K;cin>>n>>K;
    ll tot=0,sum=0;
    vi a(n),b(n);
    rep(i,n)cin>>a[i];
    cin>>tot;
    rep(i,n)cin>>b[i];
    reverse(all(a));
    rep(i,n)sum-=a[i]*(i+1);
    rep(i,n)sum+=b[i]*(i+1);
    rep(i,n)tot+=a[i];
    rep(i,n)tot+=b[i];
    sum-=K;
    if(sum<0){
        sum*=-1;swap(a,b);
    }
    ll mx=510000,mx2=250000;
    auto sol=[&](vi v){
        vi dp(mx+1,inf);dp[0]=0;
        REP(i,1,v.size()+1){
            vi ndp=dp;
            rep(j,i){
                deque<ll> deq;
                for(ll k=j;k<=mx;k+=i){
                    if(dp[k]!=inf){
                        while(deq.size()&&dp[deq.back()]-deq.back()/i>=dp[k]-k/i)deq.pop_back();
                        deq.pb(k);
                    }
                    while(deq.size()&&deq.front()<k-i*v[i-1])deq.pop_front();
                    if(deq.size())chmin(ndp[k],dp[deq.front()]+(k-deq.front())/i);
                }
            }
            dp=ndp;
        }
        return dp;
    };
    for(int i=n;i>0;i--)if(sum>mx2){
        ll mi=min(b[i-1]-i,(sum-mx2)/i+1);
        chmax(mi,0ll);
        sum-=mi*i;
        b[i-1]-=mi;
        tot-=mi;
    }
    if(sum>mx){
        out("impossible");
        return 0;
    }
    vi dpa=sol(a);
    vi dpb=sol(b);
    ll ans=inf;
    rep(i,dpa.size())if(i+sum<dpb.size())chmin(ans,dpa[i]+dpb[i+sum]);
    if(ans==inf)out("impossible");
    else out(tot-ans);
}

Compilation message

vault.cpp: In function 'int main()':
vault.cpp:74:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     rep(i,dpa.size())if(i+sum<dpb.size())chmin(ans,dpa[i]+dpb[i+sum]);
      |                         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12288 KB Output is correct
2 Correct 20 ms 12300 KB Output is correct
3 Correct 12 ms 12296 KB Output is correct
4 Correct 52 ms 12224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 288 ms 12284 KB Output is correct
7 Correct 257 ms 12276 KB Output is correct
8 Correct 272 ms 12268 KB Output is correct
9 Correct 301 ms 12272 KB Output is correct
10 Correct 254 ms 12376 KB Output is correct
11 Correct 298 ms 12284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12288 KB Output is correct
2 Correct 20 ms 12300 KB Output is correct
3 Correct 12 ms 12296 KB Output is correct
4 Correct 52 ms 12224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 288 ms 12284 KB Output is correct
7 Correct 257 ms 12276 KB Output is correct
8 Correct 272 ms 12268 KB Output is correct
9 Correct 301 ms 12272 KB Output is correct
10 Correct 254 ms 12376 KB Output is correct
11 Correct 298 ms 12284 KB Output is correct
12 Correct 15 ms 12228 KB Output is correct
13 Correct 19 ms 12224 KB Output is correct
14 Correct 11 ms 12264 KB Output is correct
15 Correct 53 ms 12240 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 296 ms 12252 KB Output is correct
18 Correct 267 ms 12276 KB Output is correct
19 Correct 323 ms 12268 KB Output is correct
20 Correct 303 ms 12272 KB Output is correct
21 Correct 285 ms 12372 KB Output is correct
22 Correct 249 ms 12252 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 812 ms 12376 KB Output is correct
25 Correct 573 ms 12252 KB Output is correct
26 Correct 1182 ms 12336 KB Output is correct
27 Incorrect 1028 ms 12252 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 12268 KB Output is correct
2 Correct 465 ms 12624 KB Output is correct
3 Correct 307 ms 12508 KB Output is correct
4 Correct 475 ms 13284 KB Output is correct
5 Correct 422 ms 12624 KB Output is correct
6 Correct 387 ms 12888 KB Output is correct
7 Correct 176 ms 12244 KB Output is correct
8 Correct 162 ms 12256 KB Output is correct
9 Correct 416 ms 12900 KB Output is correct
10 Correct 381 ms 12372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 12268 KB Output is correct
2 Correct 465 ms 12624 KB Output is correct
3 Correct 307 ms 12508 KB Output is correct
4 Correct 475 ms 13284 KB Output is correct
5 Correct 422 ms 12624 KB Output is correct
6 Correct 387 ms 12888 KB Output is correct
7 Correct 176 ms 12244 KB Output is correct
8 Correct 162 ms 12256 KB Output is correct
9 Correct 416 ms 12900 KB Output is correct
10 Correct 381 ms 12372 KB Output is correct
11 Correct 15 ms 12224 KB Output is correct
12 Correct 19 ms 12224 KB Output is correct
13 Correct 13 ms 12224 KB Output is correct
14 Correct 45 ms 12264 KB Output is correct
15 Correct 451 ms 12620 KB Output is correct
16 Correct 291 ms 12372 KB Output is correct
17 Correct 430 ms 13320 KB Output is correct
18 Correct 418 ms 12600 KB Output is correct
19 Correct 401 ms 12972 KB Output is correct
20 Correct 136 ms 12188 KB Output is correct
21 Correct 138 ms 12376 KB Output is correct
22 Correct 411 ms 12880 KB Output is correct
23 Correct 370 ms 12372 KB Output is correct
24 Correct 713 ms 12624 KB Output is correct
25 Correct 402 ms 12372 KB Output is correct
26 Correct 650 ms 12480 KB Output is correct
27 Correct 699 ms 12596 KB Output is correct
28 Correct 703 ms 13056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 12268 KB Output is correct
2 Correct 465 ms 12624 KB Output is correct
3 Correct 307 ms 12508 KB Output is correct
4 Correct 475 ms 13284 KB Output is correct
5 Correct 422 ms 12624 KB Output is correct
6 Correct 387 ms 12888 KB Output is correct
7 Correct 176 ms 12244 KB Output is correct
8 Correct 162 ms 12256 KB Output is correct
9 Correct 416 ms 12900 KB Output is correct
10 Correct 381 ms 12372 KB Output is correct
11 Correct 46 ms 12384 KB Output is correct
12 Correct 463 ms 12624 KB Output is correct
13 Correct 291 ms 12404 KB Output is correct
14 Correct 435 ms 13280 KB Output is correct
15 Correct 424 ms 12644 KB Output is correct
16 Correct 376 ms 12968 KB Output is correct
17 Correct 142 ms 12276 KB Output is correct
18 Correct 165 ms 12268 KB Output is correct
19 Correct 435 ms 12996 KB Output is correct
20 Correct 377 ms 12340 KB Output is correct
21 Correct 225 ms 12260 KB Output is correct
22 Correct 246 ms 12264 KB Output is correct
23 Correct 735 ms 12504 KB Output is correct
24 Correct 645 ms 12420 KB Output is correct
25 Correct 739 ms 12984 KB Output is correct
26 Correct 741 ms 12992 KB Output is correct
27 Correct 645 ms 12740 KB Output is correct
28 Correct 732 ms 12380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12288 KB Output is correct
2 Correct 20 ms 12300 KB Output is correct
3 Correct 12 ms 12296 KB Output is correct
4 Correct 52 ms 12224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 288 ms 12284 KB Output is correct
7 Correct 257 ms 12276 KB Output is correct
8 Correct 272 ms 12268 KB Output is correct
9 Correct 301 ms 12272 KB Output is correct
10 Correct 254 ms 12376 KB Output is correct
11 Correct 298 ms 12284 KB Output is correct
12 Correct 50 ms 12268 KB Output is correct
13 Correct 465 ms 12624 KB Output is correct
14 Correct 307 ms 12508 KB Output is correct
15 Correct 475 ms 13284 KB Output is correct
16 Correct 422 ms 12624 KB Output is correct
17 Correct 387 ms 12888 KB Output is correct
18 Correct 176 ms 12244 KB Output is correct
19 Correct 162 ms 12256 KB Output is correct
20 Correct 416 ms 12900 KB Output is correct
21 Correct 381 ms 12372 KB Output is correct
22 Correct 15 ms 12224 KB Output is correct
23 Correct 19 ms 12224 KB Output is correct
24 Correct 13 ms 12224 KB Output is correct
25 Correct 45 ms 12264 KB Output is correct
26 Correct 451 ms 12620 KB Output is correct
27 Correct 291 ms 12372 KB Output is correct
28 Correct 430 ms 13320 KB Output is correct
29 Correct 418 ms 12600 KB Output is correct
30 Correct 401 ms 12972 KB Output is correct
31 Correct 136 ms 12188 KB Output is correct
32 Correct 138 ms 12376 KB Output is correct
33 Correct 411 ms 12880 KB Output is correct
34 Correct 370 ms 12372 KB Output is correct
35 Correct 713 ms 12624 KB Output is correct
36 Correct 402 ms 12372 KB Output is correct
37 Correct 650 ms 12480 KB Output is correct
38 Correct 699 ms 12596 KB Output is correct
39 Correct 703 ms 13056 KB Output is correct
40 Correct 46 ms 12384 KB Output is correct
41 Correct 463 ms 12624 KB Output is correct
42 Correct 291 ms 12404 KB Output is correct
43 Correct 435 ms 13280 KB Output is correct
44 Correct 424 ms 12644 KB Output is correct
45 Correct 376 ms 12968 KB Output is correct
46 Correct 142 ms 12276 KB Output is correct
47 Correct 165 ms 12268 KB Output is correct
48 Correct 435 ms 12996 KB Output is correct
49 Correct 377 ms 12340 KB Output is correct
50 Correct 225 ms 12260 KB Output is correct
51 Correct 246 ms 12264 KB Output is correct
52 Correct 735 ms 12504 KB Output is correct
53 Correct 645 ms 12420 KB Output is correct
54 Correct 739 ms 12984 KB Output is correct
55 Correct 741 ms 12992 KB Output is correct
56 Correct 645 ms 12740 KB Output is correct
57 Correct 732 ms 12380 KB Output is correct
58 Correct 16 ms 12224 KB Output is correct
59 Correct 22 ms 12292 KB Output is correct
60 Correct 11 ms 12224 KB Output is correct
61 Correct 50 ms 12264 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 264 ms 12248 KB Output is correct
64 Correct 235 ms 12276 KB Output is correct
65 Correct 257 ms 12272 KB Output is correct
66 Correct 336 ms 12208 KB Output is correct
67 Correct 251 ms 12268 KB Output is correct
68 Correct 278 ms 12272 KB Output is correct
69 Correct 444 ms 12624 KB Output is correct
70 Correct 302 ms 12308 KB Output is correct
71 Correct 432 ms 13268 KB Output is correct
72 Correct 418 ms 12508 KB Output is correct
73 Correct 380 ms 12976 KB Output is correct
74 Correct 179 ms 12264 KB Output is correct
75 Correct 136 ms 12240 KB Output is correct
76 Correct 392 ms 12872 KB Output is correct
77 Correct 373 ms 12388 KB Output is correct
78 Correct 726 ms 12624 KB Output is correct
79 Correct 412 ms 12404 KB Output is correct
80 Correct 672 ms 12480 KB Output is correct
81 Correct 765 ms 12596 KB Output is correct
82 Correct 709 ms 13008 KB Output is correct
83 Correct 771 ms 12508 KB Output is correct
84 Correct 614 ms 12424 KB Output is correct
85 Correct 858 ms 12972 KB Output is correct
86 Correct 865 ms 12876 KB Output is correct
87 Correct 680 ms 12736 KB Output is correct
88 Correct 862 ms 12480 KB Output is correct
89 Correct 1318 ms 12540 KB Output is correct
90 Correct 1438 ms 12832 KB Output is correct
91 Correct 1369 ms 12924 KB Output is correct
92 Correct 1321 ms 13044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 12268 KB Output is correct
2 Correct 465 ms 12624 KB Output is correct
3 Correct 307 ms 12508 KB Output is correct
4 Correct 475 ms 13284 KB Output is correct
5 Correct 422 ms 12624 KB Output is correct
6 Correct 387 ms 12888 KB Output is correct
7 Correct 176 ms 12244 KB Output is correct
8 Correct 162 ms 12256 KB Output is correct
9 Correct 416 ms 12900 KB Output is correct
10 Correct 381 ms 12372 KB Output is correct
11 Correct 46 ms 12384 KB Output is correct
12 Correct 463 ms 12624 KB Output is correct
13 Correct 291 ms 12404 KB Output is correct
14 Correct 435 ms 13280 KB Output is correct
15 Correct 424 ms 12644 KB Output is correct
16 Correct 376 ms 12968 KB Output is correct
17 Correct 142 ms 12276 KB Output is correct
18 Correct 165 ms 12268 KB Output is correct
19 Correct 435 ms 12996 KB Output is correct
20 Correct 377 ms 12340 KB Output is correct
21 Correct 225 ms 12260 KB Output is correct
22 Correct 246 ms 12264 KB Output is correct
23 Correct 735 ms 12504 KB Output is correct
24 Correct 645 ms 12420 KB Output is correct
25 Correct 739 ms 12984 KB Output is correct
26 Correct 741 ms 12992 KB Output is correct
27 Correct 645 ms 12740 KB Output is correct
28 Correct 732 ms 12380 KB Output is correct
29 Correct 73 ms 12248 KB Output is correct
30 Correct 474 ms 12624 KB Output is correct
31 Correct 349 ms 12372 KB Output is correct
32 Correct 457 ms 13320 KB Output is correct
33 Correct 499 ms 12596 KB Output is correct
34 Correct 423 ms 12972 KB Output is correct
35 Correct 187 ms 12272 KB Output is correct
36 Correct 166 ms 12260 KB Output is correct
37 Correct 465 ms 12920 KB Output is correct
38 Correct 487 ms 12368 KB Output is correct
39 Correct 267 ms 12268 KB Output is correct
40 Correct 296 ms 12268 KB Output is correct
41 Correct 739 ms 12508 KB Output is correct
42 Correct 733 ms 12500 KB Output is correct
43 Correct 799 ms 13064 KB Output is correct
44 Correct 811 ms 12872 KB Output is correct
45 Correct 718 ms 12736 KB Output is correct
46 Correct 786 ms 12484 KB Output is correct
47 Correct 572 ms 12272 KB Output is correct
48 Correct 636 ms 12268 KB Output is correct
49 Correct 1734 ms 13324 KB Output is correct
50 Correct 1496 ms 12324 KB Output is correct
51 Correct 1914 ms 13680 KB Output is correct
52 Incorrect 1982 ms 13116 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12288 KB Output is correct
2 Correct 20 ms 12300 KB Output is correct
3 Correct 12 ms 12296 KB Output is correct
4 Correct 52 ms 12224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 288 ms 12284 KB Output is correct
7 Correct 257 ms 12276 KB Output is correct
8 Correct 272 ms 12268 KB Output is correct
9 Correct 301 ms 12272 KB Output is correct
10 Correct 254 ms 12376 KB Output is correct
11 Correct 298 ms 12284 KB Output is correct
12 Correct 15 ms 12228 KB Output is correct
13 Correct 19 ms 12224 KB Output is correct
14 Correct 11 ms 12264 KB Output is correct
15 Correct 53 ms 12240 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 296 ms 12252 KB Output is correct
18 Correct 267 ms 12276 KB Output is correct
19 Correct 323 ms 12268 KB Output is correct
20 Correct 303 ms 12272 KB Output is correct
21 Correct 285 ms 12372 KB Output is correct
22 Correct 249 ms 12252 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 812 ms 12376 KB Output is correct
25 Correct 573 ms 12252 KB Output is correct
26 Correct 1182 ms 12336 KB Output is correct
27 Incorrect 1028 ms 12252 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 12268 KB Output is correct
2 Correct 465 ms 12624 KB Output is correct
3 Correct 307 ms 12508 KB Output is correct
4 Correct 475 ms 13284 KB Output is correct
5 Correct 422 ms 12624 KB Output is correct
6 Correct 387 ms 12888 KB Output is correct
7 Correct 176 ms 12244 KB Output is correct
8 Correct 162 ms 12256 KB Output is correct
9 Correct 416 ms 12900 KB Output is correct
10 Correct 381 ms 12372 KB Output is correct
11 Correct 46 ms 12384 KB Output is correct
12 Correct 463 ms 12624 KB Output is correct
13 Correct 291 ms 12404 KB Output is correct
14 Correct 435 ms 13280 KB Output is correct
15 Correct 424 ms 12644 KB Output is correct
16 Correct 376 ms 12968 KB Output is correct
17 Correct 142 ms 12276 KB Output is correct
18 Correct 165 ms 12268 KB Output is correct
19 Correct 435 ms 12996 KB Output is correct
20 Correct 377 ms 12340 KB Output is correct
21 Correct 225 ms 12260 KB Output is correct
22 Correct 246 ms 12264 KB Output is correct
23 Correct 735 ms 12504 KB Output is correct
24 Correct 645 ms 12420 KB Output is correct
25 Correct 739 ms 12984 KB Output is correct
26 Correct 741 ms 12992 KB Output is correct
27 Correct 645 ms 12740 KB Output is correct
28 Correct 732 ms 12380 KB Output is correct
29 Correct 73 ms 12248 KB Output is correct
30 Correct 474 ms 12624 KB Output is correct
31 Correct 349 ms 12372 KB Output is correct
32 Correct 457 ms 13320 KB Output is correct
33 Correct 499 ms 12596 KB Output is correct
34 Correct 423 ms 12972 KB Output is correct
35 Correct 187 ms 12272 KB Output is correct
36 Correct 166 ms 12260 KB Output is correct
37 Correct 465 ms 12920 KB Output is correct
38 Correct 487 ms 12368 KB Output is correct
39 Correct 267 ms 12268 KB Output is correct
40 Correct 296 ms 12268 KB Output is correct
41 Correct 739 ms 12508 KB Output is correct
42 Correct 733 ms 12500 KB Output is correct
43 Correct 799 ms 13064 KB Output is correct
44 Correct 811 ms 12872 KB Output is correct
45 Correct 718 ms 12736 KB Output is correct
46 Correct 786 ms 12484 KB Output is correct
47 Correct 572 ms 12272 KB Output is correct
48 Correct 636 ms 12268 KB Output is correct
49 Correct 1734 ms 13324 KB Output is correct
50 Correct 1496 ms 12324 KB Output is correct
51 Correct 1914 ms 13680 KB Output is correct
52 Incorrect 1982 ms 13116 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12288 KB Output is correct
2 Correct 20 ms 12300 KB Output is correct
3 Correct 12 ms 12296 KB Output is correct
4 Correct 52 ms 12224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 288 ms 12284 KB Output is correct
7 Correct 257 ms 12276 KB Output is correct
8 Correct 272 ms 12268 KB Output is correct
9 Correct 301 ms 12272 KB Output is correct
10 Correct 254 ms 12376 KB Output is correct
11 Correct 298 ms 12284 KB Output is correct
12 Correct 15 ms 12228 KB Output is correct
13 Correct 19 ms 12224 KB Output is correct
14 Correct 11 ms 12264 KB Output is correct
15 Correct 53 ms 12240 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 296 ms 12252 KB Output is correct
18 Correct 267 ms 12276 KB Output is correct
19 Correct 323 ms 12268 KB Output is correct
20 Correct 303 ms 12272 KB Output is correct
21 Correct 285 ms 12372 KB Output is correct
22 Correct 249 ms 12252 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 812 ms 12376 KB Output is correct
25 Correct 573 ms 12252 KB Output is correct
26 Correct 1182 ms 12336 KB Output is correct
27 Incorrect 1028 ms 12252 KB Output isn't correct
28 Halted 0 ms 0 KB -