답안 #622339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
622339 2022-08-04T07:35:44 Z rrrr10000 Uplifting Excursion (BOI22_vault) C++14
20 / 100
2229 ms 25836 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=1000000,mx2=27000;
    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]);
      |                         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 23696 KB Output is correct
2 Correct 41 ms 23788 KB Output is correct
3 Correct 21 ms 23768 KB Output is correct
4 Correct 116 ms 23776 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 841 ms 23756 KB Output is correct
7 Correct 761 ms 23752 KB Output is correct
8 Correct 786 ms 23780 KB Output is correct
9 Incorrect 873 ms 23760 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 23696 KB Output is correct
2 Correct 41 ms 23788 KB Output is correct
3 Correct 21 ms 23768 KB Output is correct
4 Correct 116 ms 23776 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 841 ms 23756 KB Output is correct
7 Correct 761 ms 23752 KB Output is correct
8 Correct 786 ms 23780 KB Output is correct
9 Incorrect 873 ms 23760 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 23732 KB Output is correct
2 Correct 1056 ms 24396 KB Output is correct
3 Correct 729 ms 23904 KB Output is correct
4 Correct 1048 ms 25836 KB Output is correct
5 Correct 1010 ms 24320 KB Output is correct
6 Correct 929 ms 23852 KB Output is correct
7 Correct 418 ms 23780 KB Output is correct
8 Correct 487 ms 23760 KB Output is correct
9 Correct 971 ms 25068 KB Output is correct
10 Correct 942 ms 23984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 23732 KB Output is correct
2 Correct 1056 ms 24396 KB Output is correct
3 Correct 729 ms 23904 KB Output is correct
4 Correct 1048 ms 25836 KB Output is correct
5 Correct 1010 ms 24320 KB Output is correct
6 Correct 929 ms 23852 KB Output is correct
7 Correct 418 ms 23780 KB Output is correct
8 Correct 487 ms 23760 KB Output is correct
9 Correct 971 ms 25068 KB Output is correct
10 Correct 942 ms 23984 KB Output is correct
11 Correct 33 ms 23748 KB Output is correct
12 Correct 44 ms 23780 KB Output is correct
13 Correct 25 ms 23756 KB Output is correct
14 Correct 117 ms 23892 KB Output is correct
15 Correct 1102 ms 24472 KB Output is correct
16 Correct 753 ms 23936 KB Output is correct
17 Correct 1062 ms 25836 KB Output is correct
18 Correct 964 ms 24412 KB Output is correct
19 Correct 906 ms 23916 KB Output is correct
20 Correct 470 ms 23772 KB Output is correct
21 Correct 483 ms 23776 KB Output is correct
22 Correct 1036 ms 24968 KB Output is correct
23 Correct 889 ms 23996 KB Output is correct
24 Correct 1636 ms 24384 KB Output is correct
25 Correct 858 ms 23792 KB Output is correct
26 Correct 1589 ms 24188 KB Output is correct
27 Correct 1677 ms 24420 KB Output is correct
28 Correct 1673 ms 23876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 23732 KB Output is correct
2 Correct 1056 ms 24396 KB Output is correct
3 Correct 729 ms 23904 KB Output is correct
4 Correct 1048 ms 25836 KB Output is correct
5 Correct 1010 ms 24320 KB Output is correct
6 Correct 929 ms 23852 KB Output is correct
7 Correct 418 ms 23780 KB Output is correct
8 Correct 487 ms 23760 KB Output is correct
9 Correct 971 ms 25068 KB Output is correct
10 Correct 942 ms 23984 KB Output is correct
11 Correct 120 ms 23780 KB Output is correct
12 Correct 1162 ms 24472 KB Output is correct
13 Correct 824 ms 23852 KB Output is correct
14 Correct 1177 ms 25832 KB Output is correct
15 Correct 1221 ms 24396 KB Output is correct
16 Correct 1098 ms 23840 KB Output is correct
17 Correct 564 ms 23780 KB Output is correct
18 Correct 637 ms 23780 KB Output is correct
19 Correct 1182 ms 24964 KB Output is correct
20 Correct 1060 ms 23988 KB Output is correct
21 Correct 1004 ms 23784 KB Output is correct
22 Correct 1048 ms 23760 KB Output is correct
23 Correct 2202 ms 24260 KB Output is correct
24 Correct 2021 ms 24068 KB Output is correct
25 Correct 2229 ms 25156 KB Output is correct
26 Incorrect 2013 ms 24956 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 23696 KB Output is correct
2 Correct 41 ms 23788 KB Output is correct
3 Correct 21 ms 23768 KB Output is correct
4 Correct 116 ms 23776 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 841 ms 23756 KB Output is correct
7 Correct 761 ms 23752 KB Output is correct
8 Correct 786 ms 23780 KB Output is correct
9 Incorrect 873 ms 23760 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 23732 KB Output is correct
2 Correct 1056 ms 24396 KB Output is correct
3 Correct 729 ms 23904 KB Output is correct
4 Correct 1048 ms 25836 KB Output is correct
5 Correct 1010 ms 24320 KB Output is correct
6 Correct 929 ms 23852 KB Output is correct
7 Correct 418 ms 23780 KB Output is correct
8 Correct 487 ms 23760 KB Output is correct
9 Correct 971 ms 25068 KB Output is correct
10 Correct 942 ms 23984 KB Output is correct
11 Correct 120 ms 23780 KB Output is correct
12 Correct 1162 ms 24472 KB Output is correct
13 Correct 824 ms 23852 KB Output is correct
14 Correct 1177 ms 25832 KB Output is correct
15 Correct 1221 ms 24396 KB Output is correct
16 Correct 1098 ms 23840 KB Output is correct
17 Correct 564 ms 23780 KB Output is correct
18 Correct 637 ms 23780 KB Output is correct
19 Correct 1182 ms 24964 KB Output is correct
20 Correct 1060 ms 23988 KB Output is correct
21 Correct 1004 ms 23784 KB Output is correct
22 Correct 1048 ms 23760 KB Output is correct
23 Correct 2202 ms 24260 KB Output is correct
24 Correct 2021 ms 24068 KB Output is correct
25 Correct 2229 ms 25156 KB Output is correct
26 Incorrect 2013 ms 24956 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 23696 KB Output is correct
2 Correct 41 ms 23788 KB Output is correct
3 Correct 21 ms 23768 KB Output is correct
4 Correct 116 ms 23776 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 841 ms 23756 KB Output is correct
7 Correct 761 ms 23752 KB Output is correct
8 Correct 786 ms 23780 KB Output is correct
9 Incorrect 873 ms 23760 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 23732 KB Output is correct
2 Correct 1056 ms 24396 KB Output is correct
3 Correct 729 ms 23904 KB Output is correct
4 Correct 1048 ms 25836 KB Output is correct
5 Correct 1010 ms 24320 KB Output is correct
6 Correct 929 ms 23852 KB Output is correct
7 Correct 418 ms 23780 KB Output is correct
8 Correct 487 ms 23760 KB Output is correct
9 Correct 971 ms 25068 KB Output is correct
10 Correct 942 ms 23984 KB Output is correct
11 Correct 120 ms 23780 KB Output is correct
12 Correct 1162 ms 24472 KB Output is correct
13 Correct 824 ms 23852 KB Output is correct
14 Correct 1177 ms 25832 KB Output is correct
15 Correct 1221 ms 24396 KB Output is correct
16 Correct 1098 ms 23840 KB Output is correct
17 Correct 564 ms 23780 KB Output is correct
18 Correct 637 ms 23780 KB Output is correct
19 Correct 1182 ms 24964 KB Output is correct
20 Correct 1060 ms 23988 KB Output is correct
21 Correct 1004 ms 23784 KB Output is correct
22 Correct 1048 ms 23760 KB Output is correct
23 Correct 2202 ms 24260 KB Output is correct
24 Correct 2021 ms 24068 KB Output is correct
25 Correct 2229 ms 25156 KB Output is correct
26 Incorrect 2013 ms 24956 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 23696 KB Output is correct
2 Correct 41 ms 23788 KB Output is correct
3 Correct 21 ms 23768 KB Output is correct
4 Correct 116 ms 23776 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 841 ms 23756 KB Output is correct
7 Correct 761 ms 23752 KB Output is correct
8 Correct 786 ms 23780 KB Output is correct
9 Incorrect 873 ms 23760 KB Output isn't correct
10 Halted 0 ms 0 KB -