Submission #580456

# Submission time Handle Problem Language Result Execution time Memory
580456 2022-06-21T09:18:32 Z 반딧불(#8355) Uplifting Excursion (BOI22_vault) C++17
45 / 100
1322 ms 8236 KB
#include <bits/stdc++.h>
#ifndef TEST
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

using namespace std;

typedef long long ll;
const ll LIM = 100000;

void imp(){
    puts("impossible");
    exit(0);
}

ll dq1[1000002];
ll dq2[1000002];
int fr, sz;

ll f(ll x, ll y, bool b){
    if(b) return max(x, y);
    return min(x, y);
}

void calculateMax(int n, ll* arr, int lim, vector<ll>& ret){
    ret = vector<ll>(lim*2+1, -1e18);
    ret[lim] = 0;
    vector<ll> tvec (lim*2+1, -1e18);
    for(int ri=0; ri<=n+n; ri++){
        tvec.swap(ret);
        if(ri>n){
            int i = ri-n;
            for(int s=0; s<i; s++){
                fr=sz=0;
                for(int j=s, p=0; j<=lim*2; j+=i, p++){
                    ret[j] = max(ret[j], tvec[j]);
                    while(fr!=sz && dq2[fr] < p) fr++;
                    ll nf = tvec[j]-p;
                    while(fr!=sz && dq1[sz-1] < nf) sz--;
                    dq1[sz] = nf;
                    dq2[sz++] = p+arr[ri];
                    ret[j] = max(ret[j], dq1[fr] + p);
                }
            }
        }
        else if(ri<n){
            int i = n-ri;
            for(int s=0; s<i; s++){
                fr=sz=0;
                for(int j=lim*2-s, p=0; j>=0; j-=i, p++){
                    ret[j] = max(ret[j], tvec[j]);
                    while(fr!=sz && dq2[fr] < p) fr++;
                    ll nf = tvec[j]-p;
                    while(fr!=sz && dq1[sz-1] < nf) sz--;
                    dq1[sz] = nf;
                    dq2[sz++] = p+arr[ri];
                    ret[j] = max(ret[j], dq1[fr] + p);
                }
            }
        }
        else tvec.swap(ret);
    }
}

void calculateMin(int n, ll* arr, int lim, vector<ll>& ret){
    ret = vector<ll>(lim*2+1, 1e18);
    ret[lim] = 0;
    vector<ll> tvec (lim*2+1, 1e18);
    for(int ri=0; ri<=n+n; ri++){
        tvec.swap(ret);
        if(ri>n){
            int i = ri-n;
            for(int s=0; s<i; s++){
                fr=sz=0;
                for(int j=s, p=0; j<=lim*2; j+=i, p++){
                    ret[j] = min(ret[j], tvec[j]);
                    while(fr!=sz && dq2[fr] < p) fr++;
                    ll nf = tvec[j]-p;
                    while(fr!=sz && dq1[sz-1] > nf) sz--;
                    dq1[sz] = nf;
                    dq2[sz++] = p+arr[ri];
                    ret[j] = min(ret[j], dq1[fr] + p);
                }
            }
        }
        else if(ri<n){
            int i = n-ri;
            for(int s=0; s<i; s++){
                fr=sz=0;
                for(int j=lim*2-s, p=0; j>=0; j-=i, p++){
                    ret[j] = min(ret[j], tvec[j]);
                    while(fr!=sz && dq2[fr] < p) fr++;
                    ll nf = tvec[j]-p;
                    while(fr!=sz && dq1[sz-1] > nf) sz--;
                    dq1[sz] = nf;
                    dq2[sz++] = p+arr[ri];
                    ret[j] = min(ret[j], dq1[fr] + p);
                }
            }
        }
        else tvec.swap(ret);
    }
}

int n;
ll k;
ll arr[702];

ll used[702];
ll rem[702];
vector<ll> DP, DP2;

ll ans = -1e18;
ll frontCnt;

int main(){
    scanf("%lld %lld", &n, &k);
    for(int i=0; i<=n+n; i++){
        scanf("%lld", &arr[i]);
//        arr[i] = ll(rand()) * ll(rand()) * ll(rand()) * ll(rand()) % 100LL;
    }
//    printf("%lld\n", arr[1] + min(arr[0], arr[2])*2);
    if(k<0){
        k*=-1;
        reverse(arr, arr+n+n+1);
    }

    for(int i=0; i<=n+n; i++) used[i] = 0, rem[i] = arr[i];
    for(int i=n; i<=n+n; i++){
        if(k >= arr[i]*(i-n)){
            k -= arr[i]*(i-n);
            used[i] = arr[i];
            rem[i] = 0;
        }
        else{
            ll tmp = k/(i-n);
            used[i] = tmp;
            rem[i] = arr[i]-tmp;
            k -= tmp*(i-n);
        }
    }
    if(accumulate(rem, rem+n+n+1, 0LL) == 0 && k) imp();
    for(int i=1; i<=n; i++){
        ll tmp = min(rem[n-i], rem[n+i]);
        rem[n-i] -= tmp, rem[n+i] -= tmp;
        used[n-i] += tmp, used[n+i] += tmp;
    }
    frontCnt = accumulate(used, used+n+n+1, 0LL);

    calculateMax(n, rem, LIM, DP); /// �ִ�
    calculateMin(n, used, LIM, DP2); /// �ּ�

    for(ll i=0; i<=LIM+LIM; i++){
        ll j = (i-LIM)-k+LIM;
        if(0<=j && j<=LIM+LIM) ans = max(ans, frontCnt + DP[i] - DP2[j]);
    }

    if(ans <= 0) imp();
    printf("%lld", ans);
}

Compilation message

vault.cpp: In function 'int main()':
vault.cpp:119:15: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
  119 |     scanf("%lld %lld", &n, &k);
      |            ~~~^        ~~
      |               |        |
      |               |        int*
      |               long long int*
      |            %d
vault.cpp:119:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |     scanf("%lld %lld", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
vault.cpp:121:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |         scanf("%lld", &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8120 KB Output is correct
2 Correct 13 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 35 ms 8236 KB Output is correct
5 Correct 177 ms 8116 KB Output is correct
6 Correct 257 ms 8096 KB Output is correct
7 Correct 178 ms 8096 KB Output is correct
8 Correct 209 ms 8124 KB Output is correct
9 Correct 286 ms 8100 KB Output is correct
10 Correct 158 ms 8112 KB Output is correct
11 Correct 178 ms 8100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8120 KB Output is correct
2 Correct 13 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 35 ms 8236 KB Output is correct
5 Correct 177 ms 8116 KB Output is correct
6 Correct 257 ms 8096 KB Output is correct
7 Correct 178 ms 8096 KB Output is correct
8 Correct 209 ms 8124 KB Output is correct
9 Correct 286 ms 8100 KB Output is correct
10 Correct 158 ms 8112 KB Output is correct
11 Correct 178 ms 8100 KB Output is correct
12 Correct 11 ms 8120 KB Output is correct
13 Correct 16 ms 8120 KB Output is correct
14 Correct 8 ms 8104 KB Output is correct
15 Correct 44 ms 8112 KB Output is correct
16 Correct 190 ms 8096 KB Output is correct
17 Correct 268 ms 8136 KB Output is correct
18 Correct 181 ms 8148 KB Output is correct
19 Correct 193 ms 8104 KB Output is correct
20 Correct 192 ms 8120 KB Output is correct
21 Correct 196 ms 8128 KB Output is correct
22 Correct 198 ms 8116 KB Output is correct
23 Correct 415 ms 8104 KB Output is correct
24 Correct 531 ms 8120 KB Output is correct
25 Correct 482 ms 8220 KB Output is correct
26 Incorrect 517 ms 8104 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8120 KB Output is correct
2 Correct 129 ms 8096 KB Output is correct
3 Correct 117 ms 8100 KB Output is correct
4 Correct 124 ms 8100 KB Output is correct
5 Correct 135 ms 8108 KB Output is correct
6 Correct 125 ms 8100 KB Output is correct
7 Correct 135 ms 8092 KB Output is correct
8 Correct 122 ms 8112 KB Output is correct
9 Correct 127 ms 8096 KB Output is correct
10 Correct 111 ms 8060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8120 KB Output is correct
2 Correct 129 ms 8096 KB Output is correct
3 Correct 117 ms 8100 KB Output is correct
4 Correct 124 ms 8100 KB Output is correct
5 Correct 135 ms 8108 KB Output is correct
6 Correct 125 ms 8100 KB Output is correct
7 Correct 135 ms 8092 KB Output is correct
8 Correct 122 ms 8112 KB Output is correct
9 Correct 127 ms 8096 KB Output is correct
10 Correct 111 ms 8060 KB Output is correct
11 Correct 11 ms 8092 KB Output is correct
12 Correct 14 ms 8120 KB Output is correct
13 Correct 11 ms 8120 KB Output is correct
14 Correct 42 ms 8120 KB Output is correct
15 Correct 153 ms 8112 KB Output is correct
16 Correct 96 ms 8112 KB Output is correct
17 Correct 140 ms 8100 KB Output is correct
18 Correct 166 ms 8204 KB Output is correct
19 Correct 135 ms 8156 KB Output is correct
20 Correct 115 ms 8112 KB Output is correct
21 Correct 107 ms 8096 KB Output is correct
22 Correct 172 ms 8100 KB Output is correct
23 Correct 100 ms 8096 KB Output is correct
24 Incorrect 142 ms 8028 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8120 KB Output is correct
2 Correct 129 ms 8096 KB Output is correct
3 Correct 117 ms 8100 KB Output is correct
4 Correct 124 ms 8100 KB Output is correct
5 Correct 135 ms 8108 KB Output is correct
6 Correct 125 ms 8100 KB Output is correct
7 Correct 135 ms 8092 KB Output is correct
8 Correct 122 ms 8112 KB Output is correct
9 Correct 127 ms 8096 KB Output is correct
10 Correct 111 ms 8060 KB Output is correct
11 Correct 43 ms 8116 KB Output is correct
12 Correct 125 ms 8136 KB Output is correct
13 Correct 96 ms 8104 KB Output is correct
14 Correct 130 ms 8220 KB Output is correct
15 Correct 115 ms 8092 KB Output is correct
16 Correct 116 ms 8104 KB Output is correct
17 Correct 107 ms 8064 KB Output is correct
18 Correct 132 ms 8100 KB Output is correct
19 Correct 101 ms 8096 KB Output is correct
20 Correct 140 ms 8096 KB Output is correct
21 Correct 232 ms 8096 KB Output is correct
22 Correct 153 ms 8072 KB Output is correct
23 Correct 223 ms 8100 KB Output is correct
24 Correct 202 ms 8100 KB Output is correct
25 Correct 169 ms 8112 KB Output is correct
26 Correct 188 ms 8056 KB Output is correct
27 Correct 221 ms 8092 KB Output is correct
28 Correct 194 ms 8100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8120 KB Output is correct
2 Correct 13 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 35 ms 8236 KB Output is correct
5 Correct 177 ms 8116 KB Output is correct
6 Correct 257 ms 8096 KB Output is correct
7 Correct 178 ms 8096 KB Output is correct
8 Correct 209 ms 8124 KB Output is correct
9 Correct 286 ms 8100 KB Output is correct
10 Correct 158 ms 8112 KB Output is correct
11 Correct 178 ms 8100 KB Output is correct
12 Correct 38 ms 8120 KB Output is correct
13 Correct 129 ms 8096 KB Output is correct
14 Correct 117 ms 8100 KB Output is correct
15 Correct 124 ms 8100 KB Output is correct
16 Correct 135 ms 8108 KB Output is correct
17 Correct 125 ms 8100 KB Output is correct
18 Correct 135 ms 8092 KB Output is correct
19 Correct 122 ms 8112 KB Output is correct
20 Correct 127 ms 8096 KB Output is correct
21 Correct 111 ms 8060 KB Output is correct
22 Correct 11 ms 8092 KB Output is correct
23 Correct 14 ms 8120 KB Output is correct
24 Correct 11 ms 8120 KB Output is correct
25 Correct 42 ms 8120 KB Output is correct
26 Correct 153 ms 8112 KB Output is correct
27 Correct 96 ms 8112 KB Output is correct
28 Correct 140 ms 8100 KB Output is correct
29 Correct 166 ms 8204 KB Output is correct
30 Correct 135 ms 8156 KB Output is correct
31 Correct 115 ms 8112 KB Output is correct
32 Correct 107 ms 8096 KB Output is correct
33 Correct 172 ms 8100 KB Output is correct
34 Correct 100 ms 8096 KB Output is correct
35 Incorrect 142 ms 8028 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8120 KB Output is correct
2 Correct 129 ms 8096 KB Output is correct
3 Correct 117 ms 8100 KB Output is correct
4 Correct 124 ms 8100 KB Output is correct
5 Correct 135 ms 8108 KB Output is correct
6 Correct 125 ms 8100 KB Output is correct
7 Correct 135 ms 8092 KB Output is correct
8 Correct 122 ms 8112 KB Output is correct
9 Correct 127 ms 8096 KB Output is correct
10 Correct 111 ms 8060 KB Output is correct
11 Correct 43 ms 8116 KB Output is correct
12 Correct 125 ms 8136 KB Output is correct
13 Correct 96 ms 8104 KB Output is correct
14 Correct 130 ms 8220 KB Output is correct
15 Correct 115 ms 8092 KB Output is correct
16 Correct 116 ms 8104 KB Output is correct
17 Correct 107 ms 8064 KB Output is correct
18 Correct 132 ms 8100 KB Output is correct
19 Correct 101 ms 8096 KB Output is correct
20 Correct 140 ms 8096 KB Output is correct
21 Correct 232 ms 8096 KB Output is correct
22 Correct 153 ms 8072 KB Output is correct
23 Correct 223 ms 8100 KB Output is correct
24 Correct 202 ms 8100 KB Output is correct
25 Correct 169 ms 8112 KB Output is correct
26 Correct 188 ms 8056 KB Output is correct
27 Correct 221 ms 8092 KB Output is correct
28 Correct 194 ms 8100 KB Output is correct
29 Correct 34 ms 8116 KB Output is correct
30 Correct 109 ms 8124 KB Output is correct
31 Correct 91 ms 8024 KB Output is correct
32 Correct 139 ms 8092 KB Output is correct
33 Correct 110 ms 8096 KB Output is correct
34 Correct 113 ms 8076 KB Output is correct
35 Correct 121 ms 8100 KB Output is correct
36 Correct 112 ms 8108 KB Output is correct
37 Correct 120 ms 8124 KB Output is correct
38 Correct 105 ms 8228 KB Output is correct
39 Correct 169 ms 8112 KB Output is correct
40 Correct 169 ms 8100 KB Output is correct
41 Correct 213 ms 8100 KB Output is correct
42 Correct 166 ms 8096 KB Output is correct
43 Correct 257 ms 8096 KB Output is correct
44 Correct 180 ms 8104 KB Output is correct
45 Correct 176 ms 8096 KB Output is correct
46 Correct 220 ms 8152 KB Output is correct
47 Correct 392 ms 8108 KB Output is correct
48 Correct 349 ms 8084 KB Output is correct
49 Correct 426 ms 8096 KB Output is correct
50 Correct 419 ms 8108 KB Output is correct
51 Correct 358 ms 8112 KB Output is correct
52 Correct 405 ms 8080 KB Output is correct
53 Correct 373 ms 8104 KB Output is correct
54 Correct 365 ms 8216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8120 KB Output is correct
2 Correct 13 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 35 ms 8236 KB Output is correct
5 Correct 177 ms 8116 KB Output is correct
6 Correct 257 ms 8096 KB Output is correct
7 Correct 178 ms 8096 KB Output is correct
8 Correct 209 ms 8124 KB Output is correct
9 Correct 286 ms 8100 KB Output is correct
10 Correct 158 ms 8112 KB Output is correct
11 Correct 178 ms 8100 KB Output is correct
12 Correct 11 ms 8120 KB Output is correct
13 Correct 16 ms 8120 KB Output is correct
14 Correct 8 ms 8104 KB Output is correct
15 Correct 44 ms 8112 KB Output is correct
16 Correct 190 ms 8096 KB Output is correct
17 Correct 268 ms 8136 KB Output is correct
18 Correct 181 ms 8148 KB Output is correct
19 Correct 193 ms 8104 KB Output is correct
20 Correct 192 ms 8120 KB Output is correct
21 Correct 196 ms 8128 KB Output is correct
22 Correct 198 ms 8116 KB Output is correct
23 Correct 415 ms 8104 KB Output is correct
24 Correct 531 ms 8120 KB Output is correct
25 Correct 482 ms 8220 KB Output is correct
26 Incorrect 517 ms 8104 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8120 KB Output is correct
2 Correct 129 ms 8096 KB Output is correct
3 Correct 117 ms 8100 KB Output is correct
4 Correct 124 ms 8100 KB Output is correct
5 Correct 135 ms 8108 KB Output is correct
6 Correct 125 ms 8100 KB Output is correct
7 Correct 135 ms 8092 KB Output is correct
8 Correct 122 ms 8112 KB Output is correct
9 Correct 127 ms 8096 KB Output is correct
10 Correct 111 ms 8060 KB Output is correct
11 Correct 43 ms 8116 KB Output is correct
12 Correct 125 ms 8136 KB Output is correct
13 Correct 96 ms 8104 KB Output is correct
14 Correct 130 ms 8220 KB Output is correct
15 Correct 115 ms 8092 KB Output is correct
16 Correct 116 ms 8104 KB Output is correct
17 Correct 107 ms 8064 KB Output is correct
18 Correct 132 ms 8100 KB Output is correct
19 Correct 101 ms 8096 KB Output is correct
20 Correct 140 ms 8096 KB Output is correct
21 Correct 232 ms 8096 KB Output is correct
22 Correct 153 ms 8072 KB Output is correct
23 Correct 223 ms 8100 KB Output is correct
24 Correct 202 ms 8100 KB Output is correct
25 Correct 169 ms 8112 KB Output is correct
26 Correct 188 ms 8056 KB Output is correct
27 Correct 221 ms 8092 KB Output is correct
28 Correct 194 ms 8100 KB Output is correct
29 Correct 34 ms 8116 KB Output is correct
30 Correct 109 ms 8124 KB Output is correct
31 Correct 91 ms 8024 KB Output is correct
32 Correct 139 ms 8092 KB Output is correct
33 Correct 110 ms 8096 KB Output is correct
34 Correct 113 ms 8076 KB Output is correct
35 Correct 121 ms 8100 KB Output is correct
36 Correct 112 ms 8108 KB Output is correct
37 Correct 120 ms 8124 KB Output is correct
38 Correct 105 ms 8228 KB Output is correct
39 Correct 169 ms 8112 KB Output is correct
40 Correct 169 ms 8100 KB Output is correct
41 Correct 213 ms 8100 KB Output is correct
42 Correct 166 ms 8096 KB Output is correct
43 Correct 257 ms 8096 KB Output is correct
44 Correct 180 ms 8104 KB Output is correct
45 Correct 176 ms 8096 KB Output is correct
46 Correct 220 ms 8152 KB Output is correct
47 Correct 392 ms 8108 KB Output is correct
48 Correct 349 ms 8084 KB Output is correct
49 Correct 426 ms 8096 KB Output is correct
50 Correct 419 ms 8108 KB Output is correct
51 Correct 358 ms 8112 KB Output is correct
52 Correct 405 ms 8080 KB Output is correct
53 Correct 373 ms 8104 KB Output is correct
54 Correct 365 ms 8216 KB Output is correct
55 Correct 35 ms 8120 KB Output is correct
56 Correct 117 ms 8112 KB Output is correct
57 Correct 110 ms 8104 KB Output is correct
58 Correct 105 ms 8100 KB Output is correct
59 Correct 105 ms 8108 KB Output is correct
60 Correct 109 ms 8092 KB Output is correct
61 Correct 130 ms 8112 KB Output is correct
62 Correct 107 ms 8096 KB Output is correct
63 Correct 110 ms 8032 KB Output is correct
64 Correct 113 ms 8100 KB Output is correct
65 Correct 185 ms 8096 KB Output is correct
66 Correct 187 ms 8096 KB Output is correct
67 Correct 178 ms 8028 KB Output is correct
68 Correct 181 ms 8112 KB Output is correct
69 Correct 176 ms 8100 KB Output is correct
70 Correct 179 ms 8104 KB Output is correct
71 Correct 179 ms 8120 KB Output is correct
72 Correct 181 ms 8036 KB Output is correct
73 Correct 340 ms 8100 KB Output is correct
74 Correct 357 ms 8100 KB Output is correct
75 Correct 349 ms 8112 KB Output is correct
76 Correct 358 ms 8088 KB Output is correct
77 Correct 344 ms 8084 KB Output is correct
78 Correct 414 ms 8096 KB Output is correct
79 Correct 379 ms 8092 KB Output is correct
80 Correct 330 ms 8096 KB Output is correct
81 Correct 1083 ms 8052 KB Output is correct
82 Correct 1050 ms 8108 KB Output is correct
83 Correct 1083 ms 8096 KB Output is correct
84 Correct 1180 ms 8104 KB Output is correct
85 Correct 1091 ms 8100 KB Output is correct
86 Correct 1108 ms 8100 KB Output is correct
87 Correct 1322 ms 8100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8120 KB Output is correct
2 Correct 13 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 35 ms 8236 KB Output is correct
5 Correct 177 ms 8116 KB Output is correct
6 Correct 257 ms 8096 KB Output is correct
7 Correct 178 ms 8096 KB Output is correct
8 Correct 209 ms 8124 KB Output is correct
9 Correct 286 ms 8100 KB Output is correct
10 Correct 158 ms 8112 KB Output is correct
11 Correct 178 ms 8100 KB Output is correct
12 Correct 11 ms 8120 KB Output is correct
13 Correct 16 ms 8120 KB Output is correct
14 Correct 8 ms 8104 KB Output is correct
15 Correct 44 ms 8112 KB Output is correct
16 Correct 190 ms 8096 KB Output is correct
17 Correct 268 ms 8136 KB Output is correct
18 Correct 181 ms 8148 KB Output is correct
19 Correct 193 ms 8104 KB Output is correct
20 Correct 192 ms 8120 KB Output is correct
21 Correct 196 ms 8128 KB Output is correct
22 Correct 198 ms 8116 KB Output is correct
23 Correct 415 ms 8104 KB Output is correct
24 Correct 531 ms 8120 KB Output is correct
25 Correct 482 ms 8220 KB Output is correct
26 Incorrect 517 ms 8104 KB Output isn't correct
27 Halted 0 ms 0 KB -