답안 #622345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
622345 2022-08-04T07:41:56 Z rrrr10000 Uplifting Excursion (BOI22_vault) C++14
45 / 100
742 ms 6860 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=250000,mx2=120000;
    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 7 ms 6064 KB Output is correct
2 Correct 9 ms 6112 KB Output is correct
3 Correct 6 ms 6064 KB Output is correct
4 Correct 22 ms 6148 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 134 ms 6268 KB Output is correct
7 Correct 116 ms 6160 KB Output is correct
8 Correct 127 ms 6132 KB Output is correct
9 Correct 146 ms 6052 KB Output is correct
10 Correct 103 ms 6160 KB Output is correct
11 Correct 97 ms 6164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6064 KB Output is correct
2 Correct 9 ms 6112 KB Output is correct
3 Correct 6 ms 6064 KB Output is correct
4 Correct 22 ms 6148 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 134 ms 6268 KB Output is correct
7 Correct 116 ms 6160 KB Output is correct
8 Correct 127 ms 6132 KB Output is correct
9 Correct 146 ms 6052 KB Output is correct
10 Correct 103 ms 6160 KB Output is correct
11 Correct 97 ms 6164 KB Output is correct
12 Correct 9 ms 6064 KB Output is correct
13 Correct 9 ms 6064 KB Output is correct
14 Correct 5 ms 6064 KB Output is correct
15 Correct 26 ms 6144 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 131 ms 6164 KB Output is correct
18 Correct 101 ms 6164 KB Output is correct
19 Correct 112 ms 6052 KB Output is correct
20 Correct 297 ms 6168 KB Output is correct
21 Correct 98 ms 6160 KB Output is correct
22 Correct 95 ms 6164 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 517 ms 6184 KB Output is correct
25 Correct 303 ms 6168 KB Output is correct
26 Incorrect 679 ms 6172 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6064 KB Output is correct
2 Correct 209 ms 6336 KB Output is correct
3 Correct 137 ms 6184 KB Output is correct
4 Correct 286 ms 6692 KB Output is correct
5 Correct 211 ms 6260 KB Output is correct
6 Correct 184 ms 6436 KB Output is correct
7 Correct 67 ms 6136 KB Output is correct
8 Correct 64 ms 6164 KB Output is correct
9 Correct 187 ms 6464 KB Output is correct
10 Correct 189 ms 6112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6064 KB Output is correct
2 Correct 209 ms 6336 KB Output is correct
3 Correct 137 ms 6184 KB Output is correct
4 Correct 286 ms 6692 KB Output is correct
5 Correct 211 ms 6260 KB Output is correct
6 Correct 184 ms 6436 KB Output is correct
7 Correct 67 ms 6136 KB Output is correct
8 Correct 64 ms 6164 KB Output is correct
9 Correct 187 ms 6464 KB Output is correct
10 Correct 189 ms 6112 KB Output is correct
11 Correct 7 ms 6192 KB Output is correct
12 Correct 9 ms 6064 KB Output is correct
13 Correct 5 ms 6064 KB Output is correct
14 Correct 24 ms 6148 KB Output is correct
15 Correct 376 ms 6332 KB Output is correct
16 Correct 146 ms 6180 KB Output is correct
17 Correct 207 ms 6688 KB Output is correct
18 Correct 221 ms 6256 KB Output is correct
19 Correct 188 ms 6484 KB Output is correct
20 Correct 74 ms 6160 KB Output is correct
21 Correct 67 ms 6164 KB Output is correct
22 Correct 195 ms 6384 KB Output is correct
23 Correct 177 ms 6308 KB Output is correct
24 Correct 364 ms 6336 KB Output is correct
25 Correct 184 ms 6052 KB Output is correct
26 Correct 326 ms 6272 KB Output is correct
27 Correct 329 ms 6388 KB Output is correct
28 Correct 327 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6064 KB Output is correct
2 Correct 209 ms 6336 KB Output is correct
3 Correct 137 ms 6184 KB Output is correct
4 Correct 286 ms 6692 KB Output is correct
5 Correct 211 ms 6260 KB Output is correct
6 Correct 184 ms 6436 KB Output is correct
7 Correct 67 ms 6136 KB Output is correct
8 Correct 64 ms 6164 KB Output is correct
9 Correct 187 ms 6464 KB Output is correct
10 Correct 189 ms 6112 KB Output is correct
11 Correct 20 ms 6064 KB Output is correct
12 Correct 222 ms 6392 KB Output is correct
13 Correct 136 ms 6184 KB Output is correct
14 Correct 221 ms 6680 KB Output is correct
15 Correct 203 ms 6320 KB Output is correct
16 Correct 205 ms 6484 KB Output is correct
17 Correct 80 ms 6160 KB Output is correct
18 Correct 59 ms 6168 KB Output is correct
19 Correct 179 ms 6436 KB Output is correct
20 Correct 176 ms 6168 KB Output is correct
21 Correct 95 ms 6164 KB Output is correct
22 Correct 101 ms 6164 KB Output is correct
23 Correct 329 ms 6268 KB Output is correct
24 Correct 276 ms 6236 KB Output is correct
25 Correct 342 ms 6512 KB Output is correct
26 Correct 367 ms 6468 KB Output is correct
27 Correct 346 ms 6360 KB Output is correct
28 Correct 364 ms 6272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6064 KB Output is correct
2 Correct 9 ms 6112 KB Output is correct
3 Correct 6 ms 6064 KB Output is correct
4 Correct 22 ms 6148 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 134 ms 6268 KB Output is correct
7 Correct 116 ms 6160 KB Output is correct
8 Correct 127 ms 6132 KB Output is correct
9 Correct 146 ms 6052 KB Output is correct
10 Correct 103 ms 6160 KB Output is correct
11 Correct 97 ms 6164 KB Output is correct
12 Correct 22 ms 6064 KB Output is correct
13 Correct 209 ms 6336 KB Output is correct
14 Correct 137 ms 6184 KB Output is correct
15 Correct 286 ms 6692 KB Output is correct
16 Correct 211 ms 6260 KB Output is correct
17 Correct 184 ms 6436 KB Output is correct
18 Correct 67 ms 6136 KB Output is correct
19 Correct 64 ms 6164 KB Output is correct
20 Correct 187 ms 6464 KB Output is correct
21 Correct 189 ms 6112 KB Output is correct
22 Correct 7 ms 6192 KB Output is correct
23 Correct 9 ms 6064 KB Output is correct
24 Correct 5 ms 6064 KB Output is correct
25 Correct 24 ms 6148 KB Output is correct
26 Correct 376 ms 6332 KB Output is correct
27 Correct 146 ms 6180 KB Output is correct
28 Correct 207 ms 6688 KB Output is correct
29 Correct 221 ms 6256 KB Output is correct
30 Correct 188 ms 6484 KB Output is correct
31 Correct 74 ms 6160 KB Output is correct
32 Correct 67 ms 6164 KB Output is correct
33 Correct 195 ms 6384 KB Output is correct
34 Correct 177 ms 6308 KB Output is correct
35 Correct 364 ms 6336 KB Output is correct
36 Correct 184 ms 6052 KB Output is correct
37 Correct 326 ms 6272 KB Output is correct
38 Correct 329 ms 6388 KB Output is correct
39 Correct 327 ms 6604 KB Output is correct
40 Correct 20 ms 6064 KB Output is correct
41 Correct 222 ms 6392 KB Output is correct
42 Correct 136 ms 6184 KB Output is correct
43 Correct 221 ms 6680 KB Output is correct
44 Correct 203 ms 6320 KB Output is correct
45 Correct 205 ms 6484 KB Output is correct
46 Correct 80 ms 6160 KB Output is correct
47 Correct 59 ms 6168 KB Output is correct
48 Correct 179 ms 6436 KB Output is correct
49 Correct 176 ms 6168 KB Output is correct
50 Correct 95 ms 6164 KB Output is correct
51 Correct 101 ms 6164 KB Output is correct
52 Correct 329 ms 6268 KB Output is correct
53 Correct 276 ms 6236 KB Output is correct
54 Correct 342 ms 6512 KB Output is correct
55 Correct 367 ms 6468 KB Output is correct
56 Correct 346 ms 6360 KB Output is correct
57 Correct 364 ms 6272 KB Output is correct
58 Correct 7 ms 6104 KB Output is correct
59 Correct 17 ms 6188 KB Output is correct
60 Correct 6 ms 6064 KB Output is correct
61 Correct 24 ms 6188 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 151 ms 6052 KB Output is correct
64 Correct 114 ms 6052 KB Output is correct
65 Correct 130 ms 6160 KB Output is correct
66 Correct 142 ms 6268 KB Output is correct
67 Correct 115 ms 6160 KB Output is correct
68 Correct 119 ms 6140 KB Output is correct
69 Correct 216 ms 6332 KB Output is correct
70 Correct 137 ms 6188 KB Output is correct
71 Correct 218 ms 6684 KB Output is correct
72 Correct 213 ms 6308 KB Output is correct
73 Correct 199 ms 6492 KB Output is correct
74 Correct 78 ms 6144 KB Output is correct
75 Correct 61 ms 6140 KB Output is correct
76 Correct 305 ms 6464 KB Output is correct
77 Correct 183 ms 6212 KB Output is correct
78 Correct 354 ms 6340 KB Output is correct
79 Correct 188 ms 6180 KB Output is correct
80 Correct 304 ms 6184 KB Output is correct
81 Correct 335 ms 6328 KB Output is correct
82 Correct 612 ms 6476 KB Output is correct
83 Correct 341 ms 6388 KB Output is correct
84 Correct 537 ms 6140 KB Output is correct
85 Correct 500 ms 6436 KB Output is correct
86 Correct 403 ms 6464 KB Output is correct
87 Correct 311 ms 6360 KB Output is correct
88 Correct 352 ms 6268 KB Output is correct
89 Correct 584 ms 6248 KB Output is correct
90 Correct 638 ms 6436 KB Output is correct
91 Correct 636 ms 6460 KB Output is correct
92 Correct 578 ms 6520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6064 KB Output is correct
2 Correct 209 ms 6336 KB Output is correct
3 Correct 137 ms 6184 KB Output is correct
4 Correct 286 ms 6692 KB Output is correct
5 Correct 211 ms 6260 KB Output is correct
6 Correct 184 ms 6436 KB Output is correct
7 Correct 67 ms 6136 KB Output is correct
8 Correct 64 ms 6164 KB Output is correct
9 Correct 187 ms 6464 KB Output is correct
10 Correct 189 ms 6112 KB Output is correct
11 Correct 20 ms 6064 KB Output is correct
12 Correct 222 ms 6392 KB Output is correct
13 Correct 136 ms 6184 KB Output is correct
14 Correct 221 ms 6680 KB Output is correct
15 Correct 203 ms 6320 KB Output is correct
16 Correct 205 ms 6484 KB Output is correct
17 Correct 80 ms 6160 KB Output is correct
18 Correct 59 ms 6168 KB Output is correct
19 Correct 179 ms 6436 KB Output is correct
20 Correct 176 ms 6168 KB Output is correct
21 Correct 95 ms 6164 KB Output is correct
22 Correct 101 ms 6164 KB Output is correct
23 Correct 329 ms 6268 KB Output is correct
24 Correct 276 ms 6236 KB Output is correct
25 Correct 342 ms 6512 KB Output is correct
26 Correct 367 ms 6468 KB Output is correct
27 Correct 346 ms 6360 KB Output is correct
28 Correct 364 ms 6272 KB Output is correct
29 Correct 20 ms 6064 KB Output is correct
30 Correct 219 ms 6336 KB Output is correct
31 Correct 137 ms 6188 KB Output is correct
32 Correct 223 ms 6684 KB Output is correct
33 Correct 241 ms 6328 KB Output is correct
34 Correct 187 ms 6488 KB Output is correct
35 Correct 60 ms 6168 KB Output is correct
36 Correct 78 ms 6136 KB Output is correct
37 Correct 192 ms 6396 KB Output is correct
38 Correct 198 ms 6160 KB Output is correct
39 Correct 139 ms 6140 KB Output is correct
40 Correct 110 ms 6140 KB Output is correct
41 Correct 372 ms 6308 KB Output is correct
42 Correct 263 ms 6124 KB Output is correct
43 Correct 359 ms 6512 KB Output is correct
44 Correct 401 ms 6468 KB Output is correct
45 Correct 300 ms 6360 KB Output is correct
46 Correct 341 ms 6252 KB Output is correct
47 Correct 242 ms 6124 KB Output is correct
48 Correct 237 ms 6164 KB Output is correct
49 Correct 716 ms 6696 KB Output is correct
50 Correct 565 ms 6164 KB Output is correct
51 Incorrect 742 ms 6860 KB Output isn't correct
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6064 KB Output is correct
2 Correct 9 ms 6112 KB Output is correct
3 Correct 6 ms 6064 KB Output is correct
4 Correct 22 ms 6148 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 134 ms 6268 KB Output is correct
7 Correct 116 ms 6160 KB Output is correct
8 Correct 127 ms 6132 KB Output is correct
9 Correct 146 ms 6052 KB Output is correct
10 Correct 103 ms 6160 KB Output is correct
11 Correct 97 ms 6164 KB Output is correct
12 Correct 9 ms 6064 KB Output is correct
13 Correct 9 ms 6064 KB Output is correct
14 Correct 5 ms 6064 KB Output is correct
15 Correct 26 ms 6144 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 131 ms 6164 KB Output is correct
18 Correct 101 ms 6164 KB Output is correct
19 Correct 112 ms 6052 KB Output is correct
20 Correct 297 ms 6168 KB Output is correct
21 Correct 98 ms 6160 KB Output is correct
22 Correct 95 ms 6164 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 517 ms 6184 KB Output is correct
25 Correct 303 ms 6168 KB Output is correct
26 Incorrect 679 ms 6172 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6064 KB Output is correct
2 Correct 209 ms 6336 KB Output is correct
3 Correct 137 ms 6184 KB Output is correct
4 Correct 286 ms 6692 KB Output is correct
5 Correct 211 ms 6260 KB Output is correct
6 Correct 184 ms 6436 KB Output is correct
7 Correct 67 ms 6136 KB Output is correct
8 Correct 64 ms 6164 KB Output is correct
9 Correct 187 ms 6464 KB Output is correct
10 Correct 189 ms 6112 KB Output is correct
11 Correct 20 ms 6064 KB Output is correct
12 Correct 222 ms 6392 KB Output is correct
13 Correct 136 ms 6184 KB Output is correct
14 Correct 221 ms 6680 KB Output is correct
15 Correct 203 ms 6320 KB Output is correct
16 Correct 205 ms 6484 KB Output is correct
17 Correct 80 ms 6160 KB Output is correct
18 Correct 59 ms 6168 KB Output is correct
19 Correct 179 ms 6436 KB Output is correct
20 Correct 176 ms 6168 KB Output is correct
21 Correct 95 ms 6164 KB Output is correct
22 Correct 101 ms 6164 KB Output is correct
23 Correct 329 ms 6268 KB Output is correct
24 Correct 276 ms 6236 KB Output is correct
25 Correct 342 ms 6512 KB Output is correct
26 Correct 367 ms 6468 KB Output is correct
27 Correct 346 ms 6360 KB Output is correct
28 Correct 364 ms 6272 KB Output is correct
29 Correct 20 ms 6064 KB Output is correct
30 Correct 219 ms 6336 KB Output is correct
31 Correct 137 ms 6188 KB Output is correct
32 Correct 223 ms 6684 KB Output is correct
33 Correct 241 ms 6328 KB Output is correct
34 Correct 187 ms 6488 KB Output is correct
35 Correct 60 ms 6168 KB Output is correct
36 Correct 78 ms 6136 KB Output is correct
37 Correct 192 ms 6396 KB Output is correct
38 Correct 198 ms 6160 KB Output is correct
39 Correct 139 ms 6140 KB Output is correct
40 Correct 110 ms 6140 KB Output is correct
41 Correct 372 ms 6308 KB Output is correct
42 Correct 263 ms 6124 KB Output is correct
43 Correct 359 ms 6512 KB Output is correct
44 Correct 401 ms 6468 KB Output is correct
45 Correct 300 ms 6360 KB Output is correct
46 Correct 341 ms 6252 KB Output is correct
47 Correct 242 ms 6124 KB Output is correct
48 Correct 237 ms 6164 KB Output is correct
49 Correct 716 ms 6696 KB Output is correct
50 Correct 565 ms 6164 KB Output is correct
51 Incorrect 742 ms 6860 KB Output isn't correct
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6064 KB Output is correct
2 Correct 9 ms 6112 KB Output is correct
3 Correct 6 ms 6064 KB Output is correct
4 Correct 22 ms 6148 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 134 ms 6268 KB Output is correct
7 Correct 116 ms 6160 KB Output is correct
8 Correct 127 ms 6132 KB Output is correct
9 Correct 146 ms 6052 KB Output is correct
10 Correct 103 ms 6160 KB Output is correct
11 Correct 97 ms 6164 KB Output is correct
12 Correct 9 ms 6064 KB Output is correct
13 Correct 9 ms 6064 KB Output is correct
14 Correct 5 ms 6064 KB Output is correct
15 Correct 26 ms 6144 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 131 ms 6164 KB Output is correct
18 Correct 101 ms 6164 KB Output is correct
19 Correct 112 ms 6052 KB Output is correct
20 Correct 297 ms 6168 KB Output is correct
21 Correct 98 ms 6160 KB Output is correct
22 Correct 95 ms 6164 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 517 ms 6184 KB Output is correct
25 Correct 303 ms 6168 KB Output is correct
26 Incorrect 679 ms 6172 KB Output isn't correct
27 Halted 0 ms 0 KB -