Submission #622355

# Submission time Handle Problem Language Result Execution time Memory
622355 2022-08-04T07:57:00 Z rrrr10000 Uplifting Excursion (BOI22_vault) C++14
0 / 100
49 ms 1032 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=46000,mx2=450000;
    auto sol=[&](vi v){
        vi dp(mx+1,inf);dp[0]=0;
        REP(i,1,v.size()+1){
            rep(j,i){
                deque<P> deq;
                for(ll k=j;k<=mx;k+=i){
                    if(dp[k]!=inf){
                        while(deq.size()&&deq.back().se>=dp[k]-k/i)deq.pop_back();
                        deq.pb(k,dp[k]-k/i);
                    }
                    while(deq.size()&&deq.front().fi<k-i*v[i-1])deq.pop_front();
                    if(deq.size())chmin(dp[k],deq.front().se+k/i);
                }
            }
        }
        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:72: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]
   72 |     rep(i,dpa.size())if(i+sum<dpb.size())chmin(ans,dpa[i]+dpb[i+sum]);
      |                         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 3 ms 980 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 28 ms 1012 KB Output is correct
7 Correct 20 ms 1028 KB Output is correct
8 Correct 49 ms 1016 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 3 ms 980 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 28 ms 1012 KB Output is correct
7 Correct 20 ms 1028 KB Output is correct
8 Correct 49 ms 1016 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1024 KB Output is correct
2 Correct 27 ms 980 KB Output is correct
3 Correct 18 ms 1032 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1024 KB Output is correct
2 Correct 27 ms 980 KB Output is correct
3 Correct 18 ms 1032 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1024 KB Output is correct
2 Correct 27 ms 980 KB Output is correct
3 Correct 18 ms 1032 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 3 ms 980 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 28 ms 1012 KB Output is correct
7 Correct 20 ms 1028 KB Output is correct
8 Correct 49 ms 1016 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1024 KB Output is correct
2 Correct 27 ms 980 KB Output is correct
3 Correct 18 ms 1032 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 3 ms 980 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 28 ms 1012 KB Output is correct
7 Correct 20 ms 1028 KB Output is correct
8 Correct 49 ms 1016 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1024 KB Output is correct
2 Correct 27 ms 980 KB Output is correct
3 Correct 18 ms 1032 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 3 ms 980 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 28 ms 1012 KB Output is correct
7 Correct 20 ms 1028 KB Output is correct
8 Correct 49 ms 1016 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -