Submission #622341

# Submission time Handle Problem Language Result Execution time Memory
622341 2022-08-04T07:36:21 Z rrrr10000 Uplifting Excursion (BOI22_vault) C++14
15 / 100
5000 ms 76896 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=3000000,mx2=1000000;
    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 142 ms 70748 KB Output is correct
2 Correct 133 ms 70684 KB Output is correct
3 Correct 70 ms 70668 KB Output is correct
4 Correct 487 ms 70740 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 3719 ms 70744 KB Output is correct
7 Correct 3442 ms 70736 KB Output is correct
8 Correct 3689 ms 70736 KB Output is correct
9 Correct 3473 ms 70736 KB Output is correct
10 Correct 2918 ms 70688 KB Output is correct
11 Correct 2940 ms 70684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 70748 KB Output is correct
2 Correct 133 ms 70684 KB Output is correct
3 Correct 70 ms 70668 KB Output is correct
4 Correct 487 ms 70740 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 3719 ms 70744 KB Output is correct
7 Correct 3442 ms 70736 KB Output is correct
8 Correct 3689 ms 70736 KB Output is correct
9 Correct 3473 ms 70736 KB Output is correct
10 Correct 2918 ms 70688 KB Output is correct
11 Correct 2940 ms 70684 KB Output is correct
12 Correct 92 ms 70620 KB Output is correct
13 Correct 133 ms 70740 KB Output is correct
14 Correct 71 ms 70680 KB Output is correct
15 Correct 349 ms 70756 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2931 ms 70680 KB Output is correct
18 Correct 2825 ms 70744 KB Output is correct
19 Correct 2771 ms 70684 KB Output is correct
20 Correct 2929 ms 70688 KB Output is correct
21 Correct 2814 ms 70736 KB Output is correct
22 Correct 2876 ms 70688 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Execution timed out 5070 ms 70684 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 365 ms 70708 KB Output is correct
2 Correct 3300 ms 72800 KB Output is correct
3 Correct 2400 ms 71296 KB Output is correct
4 Correct 3286 ms 76896 KB Output is correct
5 Correct 3049 ms 72644 KB Output is correct
6 Correct 2818 ms 73588 KB Output is correct
7 Correct 1487 ms 70744 KB Output is correct
8 Correct 1674 ms 70740 KB Output is correct
9 Correct 2913 ms 74256 KB Output is correct
10 Correct 2718 ms 71376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 70708 KB Output is correct
2 Correct 3300 ms 72800 KB Output is correct
3 Correct 2400 ms 71296 KB Output is correct
4 Correct 3286 ms 76896 KB Output is correct
5 Correct 3049 ms 72644 KB Output is correct
6 Correct 2818 ms 73588 KB Output is correct
7 Correct 1487 ms 70744 KB Output is correct
8 Correct 1674 ms 70740 KB Output is correct
9 Correct 2913 ms 74256 KB Output is correct
10 Correct 2718 ms 71376 KB Output is correct
11 Correct 88 ms 70688 KB Output is correct
12 Correct 121 ms 70628 KB Output is correct
13 Correct 62 ms 70704 KB Output is correct
14 Correct 334 ms 70668 KB Output is correct
15 Correct 3525 ms 72800 KB Output is correct
16 Correct 2302 ms 71196 KB Output is correct
17 Correct 3370 ms 76824 KB Output is correct
18 Correct 3403 ms 72588 KB Output is correct
19 Correct 3570 ms 73588 KB Output is correct
20 Correct 1838 ms 70744 KB Output is correct
21 Correct 1828 ms 70740 KB Output is correct
22 Correct 3471 ms 74272 KB Output is correct
23 Correct 3211 ms 71368 KB Output is correct
24 Execution timed out 5064 ms 72792 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 365 ms 70708 KB Output is correct
2 Correct 3300 ms 72800 KB Output is correct
3 Correct 2400 ms 71296 KB Output is correct
4 Correct 3286 ms 76896 KB Output is correct
5 Correct 3049 ms 72644 KB Output is correct
6 Correct 2818 ms 73588 KB Output is correct
7 Correct 1487 ms 70744 KB Output is correct
8 Correct 1674 ms 70740 KB Output is correct
9 Correct 2913 ms 74256 KB Output is correct
10 Correct 2718 ms 71376 KB Output is correct
11 Correct 416 ms 70744 KB Output is correct
12 Correct 3857 ms 72804 KB Output is correct
13 Correct 2619 ms 71120 KB Output is correct
14 Correct 3565 ms 76896 KB Output is correct
15 Correct 3475 ms 72608 KB Output is correct
16 Correct 3254 ms 73584 KB Output is correct
17 Correct 1798 ms 70744 KB Output is correct
18 Correct 1761 ms 70740 KB Output is correct
19 Correct 3445 ms 74260 KB Output is correct
20 Correct 3396 ms 71364 KB Output is correct
21 Correct 3272 ms 70684 KB Output is correct
22 Correct 3476 ms 70740 KB Output is correct
23 Execution timed out 5036 ms 72088 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 142 ms 70748 KB Output is correct
2 Correct 133 ms 70684 KB Output is correct
3 Correct 70 ms 70668 KB Output is correct
4 Correct 487 ms 70740 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 3719 ms 70744 KB Output is correct
7 Correct 3442 ms 70736 KB Output is correct
8 Correct 3689 ms 70736 KB Output is correct
9 Correct 3473 ms 70736 KB Output is correct
10 Correct 2918 ms 70688 KB Output is correct
11 Correct 2940 ms 70684 KB Output is correct
12 Correct 365 ms 70708 KB Output is correct
13 Correct 3300 ms 72800 KB Output is correct
14 Correct 2400 ms 71296 KB Output is correct
15 Correct 3286 ms 76896 KB Output is correct
16 Correct 3049 ms 72644 KB Output is correct
17 Correct 2818 ms 73588 KB Output is correct
18 Correct 1487 ms 70744 KB Output is correct
19 Correct 1674 ms 70740 KB Output is correct
20 Correct 2913 ms 74256 KB Output is correct
21 Correct 2718 ms 71376 KB Output is correct
22 Correct 88 ms 70688 KB Output is correct
23 Correct 121 ms 70628 KB Output is correct
24 Correct 62 ms 70704 KB Output is correct
25 Correct 334 ms 70668 KB Output is correct
26 Correct 3525 ms 72800 KB Output is correct
27 Correct 2302 ms 71196 KB Output is correct
28 Correct 3370 ms 76824 KB Output is correct
29 Correct 3403 ms 72588 KB Output is correct
30 Correct 3570 ms 73588 KB Output is correct
31 Correct 1838 ms 70744 KB Output is correct
32 Correct 1828 ms 70740 KB Output is correct
33 Correct 3471 ms 74272 KB Output is correct
34 Correct 3211 ms 71368 KB Output is correct
35 Execution timed out 5064 ms 72792 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 365 ms 70708 KB Output is correct
2 Correct 3300 ms 72800 KB Output is correct
3 Correct 2400 ms 71296 KB Output is correct
4 Correct 3286 ms 76896 KB Output is correct
5 Correct 3049 ms 72644 KB Output is correct
6 Correct 2818 ms 73588 KB Output is correct
7 Correct 1487 ms 70744 KB Output is correct
8 Correct 1674 ms 70740 KB Output is correct
9 Correct 2913 ms 74256 KB Output is correct
10 Correct 2718 ms 71376 KB Output is correct
11 Correct 416 ms 70744 KB Output is correct
12 Correct 3857 ms 72804 KB Output is correct
13 Correct 2619 ms 71120 KB Output is correct
14 Correct 3565 ms 76896 KB Output is correct
15 Correct 3475 ms 72608 KB Output is correct
16 Correct 3254 ms 73584 KB Output is correct
17 Correct 1798 ms 70744 KB Output is correct
18 Correct 1761 ms 70740 KB Output is correct
19 Correct 3445 ms 74260 KB Output is correct
20 Correct 3396 ms 71364 KB Output is correct
21 Correct 3272 ms 70684 KB Output is correct
22 Correct 3476 ms 70740 KB Output is correct
23 Execution timed out 5036 ms 72088 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 142 ms 70748 KB Output is correct
2 Correct 133 ms 70684 KB Output is correct
3 Correct 70 ms 70668 KB Output is correct
4 Correct 487 ms 70740 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 3719 ms 70744 KB Output is correct
7 Correct 3442 ms 70736 KB Output is correct
8 Correct 3689 ms 70736 KB Output is correct
9 Correct 3473 ms 70736 KB Output is correct
10 Correct 2918 ms 70688 KB Output is correct
11 Correct 2940 ms 70684 KB Output is correct
12 Correct 92 ms 70620 KB Output is correct
13 Correct 133 ms 70740 KB Output is correct
14 Correct 71 ms 70680 KB Output is correct
15 Correct 349 ms 70756 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2931 ms 70680 KB Output is correct
18 Correct 2825 ms 70744 KB Output is correct
19 Correct 2771 ms 70684 KB Output is correct
20 Correct 2929 ms 70688 KB Output is correct
21 Correct 2814 ms 70736 KB Output is correct
22 Correct 2876 ms 70688 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Execution timed out 5070 ms 70684 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 365 ms 70708 KB Output is correct
2 Correct 3300 ms 72800 KB Output is correct
3 Correct 2400 ms 71296 KB Output is correct
4 Correct 3286 ms 76896 KB Output is correct
5 Correct 3049 ms 72644 KB Output is correct
6 Correct 2818 ms 73588 KB Output is correct
7 Correct 1487 ms 70744 KB Output is correct
8 Correct 1674 ms 70740 KB Output is correct
9 Correct 2913 ms 74256 KB Output is correct
10 Correct 2718 ms 71376 KB Output is correct
11 Correct 416 ms 70744 KB Output is correct
12 Correct 3857 ms 72804 KB Output is correct
13 Correct 2619 ms 71120 KB Output is correct
14 Correct 3565 ms 76896 KB Output is correct
15 Correct 3475 ms 72608 KB Output is correct
16 Correct 3254 ms 73584 KB Output is correct
17 Correct 1798 ms 70744 KB Output is correct
18 Correct 1761 ms 70740 KB Output is correct
19 Correct 3445 ms 74260 KB Output is correct
20 Correct 3396 ms 71364 KB Output is correct
21 Correct 3272 ms 70684 KB Output is correct
22 Correct 3476 ms 70740 KB Output is correct
23 Execution timed out 5036 ms 72088 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 142 ms 70748 KB Output is correct
2 Correct 133 ms 70684 KB Output is correct
3 Correct 70 ms 70668 KB Output is correct
4 Correct 487 ms 70740 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 3719 ms 70744 KB Output is correct
7 Correct 3442 ms 70736 KB Output is correct
8 Correct 3689 ms 70736 KB Output is correct
9 Correct 3473 ms 70736 KB Output is correct
10 Correct 2918 ms 70688 KB Output is correct
11 Correct 2940 ms 70684 KB Output is correct
12 Correct 92 ms 70620 KB Output is correct
13 Correct 133 ms 70740 KB Output is correct
14 Correct 71 ms 70680 KB Output is correct
15 Correct 349 ms 70756 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2931 ms 70680 KB Output is correct
18 Correct 2825 ms 70744 KB Output is correct
19 Correct 2771 ms 70684 KB Output is correct
20 Correct 2929 ms 70688 KB Output is correct
21 Correct 2814 ms 70736 KB Output is correct
22 Correct 2876 ms 70688 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Execution timed out 5070 ms 70684 KB Time limit exceeded
25 Halted 0 ms 0 KB -