Submission #580446

# Submission time Handle Problem Language Result Execution time Memory
580446 2022-06-21T09:07:56 Z 반딧불(#8355) Uplifting Excursion (BOI22_vault) C++17
35 / 100
520 ms 8248 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[302];

ll used[302];
ll rem[302];
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) 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 15 ms 8188 KB Output is correct
2 Correct 17 ms 8120 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 37 ms 8096 KB Output is correct
5 Correct 192 ms 8144 KB Output is correct
6 Correct 212 ms 8080 KB Output is correct
7 Correct 189 ms 8152 KB Output is correct
8 Correct 244 ms 8040 KB Output is correct
9 Correct 182 ms 8132 KB Output is correct
10 Correct 227 ms 8028 KB Output is correct
11 Correct 158 ms 8080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8188 KB Output is correct
2 Correct 17 ms 8120 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 37 ms 8096 KB Output is correct
5 Correct 192 ms 8144 KB Output is correct
6 Correct 212 ms 8080 KB Output is correct
7 Correct 189 ms 8152 KB Output is correct
8 Correct 244 ms 8040 KB Output is correct
9 Correct 182 ms 8132 KB Output is correct
10 Correct 227 ms 8028 KB Output is correct
11 Correct 158 ms 8080 KB Output is correct
12 Correct 10 ms 8120 KB Output is correct
13 Correct 14 ms 8096 KB Output is correct
14 Correct 8 ms 8120 KB Output is correct
15 Correct 34 ms 8120 KB Output is correct
16 Correct 197 ms 8080 KB Output is correct
17 Correct 205 ms 8108 KB Output is correct
18 Correct 239 ms 8108 KB Output is correct
19 Correct 196 ms 8116 KB Output is correct
20 Correct 181 ms 8112 KB Output is correct
21 Correct 163 ms 8112 KB Output is correct
22 Correct 171 ms 8112 KB Output is correct
23 Correct 492 ms 8080 KB Output is correct
24 Correct 412 ms 8112 KB Output is correct
25 Correct 412 ms 8068 KB Output is correct
26 Incorrect 452 ms 8080 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8120 KB Output is correct
2 Correct 147 ms 8084 KB Output is correct
3 Correct 126 ms 8092 KB Output is correct
4 Correct 122 ms 8084 KB Output is correct
5 Correct 114 ms 8096 KB Output is correct
6 Correct 108 ms 8116 KB Output is correct
7 Correct 99 ms 8076 KB Output is correct
8 Correct 117 ms 8112 KB Output is correct
9 Correct 107 ms 8084 KB Output is correct
10 Correct 101 ms 8076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8120 KB Output is correct
2 Correct 147 ms 8084 KB Output is correct
3 Correct 126 ms 8092 KB Output is correct
4 Correct 122 ms 8084 KB Output is correct
5 Correct 114 ms 8096 KB Output is correct
6 Correct 108 ms 8116 KB Output is correct
7 Correct 99 ms 8076 KB Output is correct
8 Correct 117 ms 8112 KB Output is correct
9 Correct 107 ms 8084 KB Output is correct
10 Correct 101 ms 8076 KB Output is correct
11 Correct 13 ms 8080 KB Output is correct
12 Correct 12 ms 8072 KB Output is correct
13 Correct 8 ms 8248 KB Output is correct
14 Correct 43 ms 8056 KB Output is correct
15 Correct 116 ms 8088 KB Output is correct
16 Correct 117 ms 8084 KB Output is correct
17 Correct 105 ms 8076 KB Output is correct
18 Correct 100 ms 8112 KB Output is correct
19 Correct 102 ms 8024 KB Output is correct
20 Correct 108 ms 8120 KB Output is correct
21 Correct 122 ms 8080 KB Output is correct
22 Correct 95 ms 8076 KB Output is correct
23 Correct 121 ms 8112 KB Output is correct
24 Incorrect 168 ms 8080 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8120 KB Output is correct
2 Correct 147 ms 8084 KB Output is correct
3 Correct 126 ms 8092 KB Output is correct
4 Correct 122 ms 8084 KB Output is correct
5 Correct 114 ms 8096 KB Output is correct
6 Correct 108 ms 8116 KB Output is correct
7 Correct 99 ms 8076 KB Output is correct
8 Correct 117 ms 8112 KB Output is correct
9 Correct 107 ms 8084 KB Output is correct
10 Correct 101 ms 8076 KB Output is correct
11 Correct 35 ms 8120 KB Output is correct
12 Correct 105 ms 8096 KB Output is correct
13 Correct 109 ms 8084 KB Output is correct
14 Correct 143 ms 8084 KB Output is correct
15 Correct 132 ms 8076 KB Output is correct
16 Correct 99 ms 8112 KB Output is correct
17 Correct 122 ms 8092 KB Output is correct
18 Correct 124 ms 8040 KB Output is correct
19 Correct 126 ms 8028 KB Output is correct
20 Correct 100 ms 8080 KB Output is correct
21 Correct 197 ms 8128 KB Output is correct
22 Correct 226 ms 8120 KB Output is correct
23 Correct 183 ms 8128 KB Output is correct
24 Correct 173 ms 8120 KB Output is correct
25 Correct 184 ms 8172 KB Output is correct
26 Correct 202 ms 8112 KB Output is correct
27 Correct 209 ms 8020 KB Output is correct
28 Correct 226 ms 8036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8188 KB Output is correct
2 Correct 17 ms 8120 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 37 ms 8096 KB Output is correct
5 Correct 192 ms 8144 KB Output is correct
6 Correct 212 ms 8080 KB Output is correct
7 Correct 189 ms 8152 KB Output is correct
8 Correct 244 ms 8040 KB Output is correct
9 Correct 182 ms 8132 KB Output is correct
10 Correct 227 ms 8028 KB Output is correct
11 Correct 158 ms 8080 KB Output is correct
12 Correct 48 ms 8120 KB Output is correct
13 Correct 147 ms 8084 KB Output is correct
14 Correct 126 ms 8092 KB Output is correct
15 Correct 122 ms 8084 KB Output is correct
16 Correct 114 ms 8096 KB Output is correct
17 Correct 108 ms 8116 KB Output is correct
18 Correct 99 ms 8076 KB Output is correct
19 Correct 117 ms 8112 KB Output is correct
20 Correct 107 ms 8084 KB Output is correct
21 Correct 101 ms 8076 KB Output is correct
22 Correct 13 ms 8080 KB Output is correct
23 Correct 12 ms 8072 KB Output is correct
24 Correct 8 ms 8248 KB Output is correct
25 Correct 43 ms 8056 KB Output is correct
26 Correct 116 ms 8088 KB Output is correct
27 Correct 117 ms 8084 KB Output is correct
28 Correct 105 ms 8076 KB Output is correct
29 Correct 100 ms 8112 KB Output is correct
30 Correct 102 ms 8024 KB Output is correct
31 Correct 108 ms 8120 KB Output is correct
32 Correct 122 ms 8080 KB Output is correct
33 Correct 95 ms 8076 KB Output is correct
34 Correct 121 ms 8112 KB Output is correct
35 Incorrect 168 ms 8080 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8120 KB Output is correct
2 Correct 147 ms 8084 KB Output is correct
3 Correct 126 ms 8092 KB Output is correct
4 Correct 122 ms 8084 KB Output is correct
5 Correct 114 ms 8096 KB Output is correct
6 Correct 108 ms 8116 KB Output is correct
7 Correct 99 ms 8076 KB Output is correct
8 Correct 117 ms 8112 KB Output is correct
9 Correct 107 ms 8084 KB Output is correct
10 Correct 101 ms 8076 KB Output is correct
11 Correct 35 ms 8120 KB Output is correct
12 Correct 105 ms 8096 KB Output is correct
13 Correct 109 ms 8084 KB Output is correct
14 Correct 143 ms 8084 KB Output is correct
15 Correct 132 ms 8076 KB Output is correct
16 Correct 99 ms 8112 KB Output is correct
17 Correct 122 ms 8092 KB Output is correct
18 Correct 124 ms 8040 KB Output is correct
19 Correct 126 ms 8028 KB Output is correct
20 Correct 100 ms 8080 KB Output is correct
21 Correct 197 ms 8128 KB Output is correct
22 Correct 226 ms 8120 KB Output is correct
23 Correct 183 ms 8128 KB Output is correct
24 Correct 173 ms 8120 KB Output is correct
25 Correct 184 ms 8172 KB Output is correct
26 Correct 202 ms 8112 KB Output is correct
27 Correct 209 ms 8020 KB Output is correct
28 Correct 226 ms 8036 KB Output is correct
29 Correct 40 ms 8100 KB Output is correct
30 Correct 122 ms 8084 KB Output is correct
31 Correct 101 ms 8084 KB Output is correct
32 Correct 145 ms 8108 KB Output is correct
33 Correct 101 ms 8040 KB Output is correct
34 Correct 139 ms 8084 KB Output is correct
35 Correct 142 ms 8100 KB Output is correct
36 Correct 115 ms 8088 KB Output is correct
37 Correct 121 ms 8100 KB Output is correct
38 Correct 139 ms 8084 KB Output is correct
39 Correct 181 ms 8060 KB Output is correct
40 Correct 181 ms 8112 KB Output is correct
41 Correct 201 ms 8108 KB Output is correct
42 Correct 232 ms 8112 KB Output is correct
43 Correct 232 ms 8084 KB Output is correct
44 Correct 194 ms 8036 KB Output is correct
45 Correct 171 ms 8084 KB Output is correct
46 Correct 266 ms 8108 KB Output is correct
47 Correct 359 ms 8116 KB Output is correct
48 Correct 339 ms 8076 KB Output is correct
49 Correct 351 ms 8080 KB Output is correct
50 Correct 441 ms 8064 KB Output is correct
51 Correct 356 ms 8080 KB Output is correct
52 Correct 414 ms 8088 KB Output is correct
53 Correct 389 ms 8096 KB Output is correct
54 Correct 485 ms 8088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8188 KB Output is correct
2 Correct 17 ms 8120 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 37 ms 8096 KB Output is correct
5 Correct 192 ms 8144 KB Output is correct
6 Correct 212 ms 8080 KB Output is correct
7 Correct 189 ms 8152 KB Output is correct
8 Correct 244 ms 8040 KB Output is correct
9 Correct 182 ms 8132 KB Output is correct
10 Correct 227 ms 8028 KB Output is correct
11 Correct 158 ms 8080 KB Output is correct
12 Correct 10 ms 8120 KB Output is correct
13 Correct 14 ms 8096 KB Output is correct
14 Correct 8 ms 8120 KB Output is correct
15 Correct 34 ms 8120 KB Output is correct
16 Correct 197 ms 8080 KB Output is correct
17 Correct 205 ms 8108 KB Output is correct
18 Correct 239 ms 8108 KB Output is correct
19 Correct 196 ms 8116 KB Output is correct
20 Correct 181 ms 8112 KB Output is correct
21 Correct 163 ms 8112 KB Output is correct
22 Correct 171 ms 8112 KB Output is correct
23 Correct 492 ms 8080 KB Output is correct
24 Correct 412 ms 8112 KB Output is correct
25 Correct 412 ms 8068 KB Output is correct
26 Incorrect 452 ms 8080 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8120 KB Output is correct
2 Correct 147 ms 8084 KB Output is correct
3 Correct 126 ms 8092 KB Output is correct
4 Correct 122 ms 8084 KB Output is correct
5 Correct 114 ms 8096 KB Output is correct
6 Correct 108 ms 8116 KB Output is correct
7 Correct 99 ms 8076 KB Output is correct
8 Correct 117 ms 8112 KB Output is correct
9 Correct 107 ms 8084 KB Output is correct
10 Correct 101 ms 8076 KB Output is correct
11 Correct 35 ms 8120 KB Output is correct
12 Correct 105 ms 8096 KB Output is correct
13 Correct 109 ms 8084 KB Output is correct
14 Correct 143 ms 8084 KB Output is correct
15 Correct 132 ms 8076 KB Output is correct
16 Correct 99 ms 8112 KB Output is correct
17 Correct 122 ms 8092 KB Output is correct
18 Correct 124 ms 8040 KB Output is correct
19 Correct 126 ms 8028 KB Output is correct
20 Correct 100 ms 8080 KB Output is correct
21 Correct 197 ms 8128 KB Output is correct
22 Correct 226 ms 8120 KB Output is correct
23 Correct 183 ms 8128 KB Output is correct
24 Correct 173 ms 8120 KB Output is correct
25 Correct 184 ms 8172 KB Output is correct
26 Correct 202 ms 8112 KB Output is correct
27 Correct 209 ms 8020 KB Output is correct
28 Correct 226 ms 8036 KB Output is correct
29 Correct 40 ms 8100 KB Output is correct
30 Correct 122 ms 8084 KB Output is correct
31 Correct 101 ms 8084 KB Output is correct
32 Correct 145 ms 8108 KB Output is correct
33 Correct 101 ms 8040 KB Output is correct
34 Correct 139 ms 8084 KB Output is correct
35 Correct 142 ms 8100 KB Output is correct
36 Correct 115 ms 8088 KB Output is correct
37 Correct 121 ms 8100 KB Output is correct
38 Correct 139 ms 8084 KB Output is correct
39 Correct 181 ms 8060 KB Output is correct
40 Correct 181 ms 8112 KB Output is correct
41 Correct 201 ms 8108 KB Output is correct
42 Correct 232 ms 8112 KB Output is correct
43 Correct 232 ms 8084 KB Output is correct
44 Correct 194 ms 8036 KB Output is correct
45 Correct 171 ms 8084 KB Output is correct
46 Correct 266 ms 8108 KB Output is correct
47 Correct 359 ms 8116 KB Output is correct
48 Correct 339 ms 8076 KB Output is correct
49 Correct 351 ms 8080 KB Output is correct
50 Correct 441 ms 8064 KB Output is correct
51 Correct 356 ms 8080 KB Output is correct
52 Correct 414 ms 8088 KB Output is correct
53 Correct 389 ms 8096 KB Output is correct
54 Correct 485 ms 8088 KB Output is correct
55 Correct 39 ms 8120 KB Output is correct
56 Correct 122 ms 8080 KB Output is correct
57 Correct 117 ms 8024 KB Output is correct
58 Correct 138 ms 8080 KB Output is correct
59 Correct 109 ms 8064 KB Output is correct
60 Correct 98 ms 8048 KB Output is correct
61 Correct 93 ms 8084 KB Output is correct
62 Correct 116 ms 8124 KB Output is correct
63 Correct 143 ms 8144 KB Output is correct
64 Correct 143 ms 8080 KB Output is correct
65 Correct 180 ms 8084 KB Output is correct
66 Correct 240 ms 8096 KB Output is correct
67 Correct 200 ms 8084 KB Output is correct
68 Correct 166 ms 8052 KB Output is correct
69 Correct 260 ms 8012 KB Output is correct
70 Correct 173 ms 8040 KB Output is correct
71 Correct 183 ms 8072 KB Output is correct
72 Correct 276 ms 8044 KB Output is correct
73 Correct 338 ms 8072 KB Output is correct
74 Correct 398 ms 8064 KB Output is correct
75 Correct 353 ms 8100 KB Output is correct
76 Correct 520 ms 8044 KB Output is correct
77 Correct 432 ms 8084 KB Output is correct
78 Correct 389 ms 8080 KB Output is correct
79 Correct 334 ms 8080 KB Output is correct
80 Correct 407 ms 8088 KB Output is correct
81 Runtime error 3 ms 468 KB Execution killed with signal 11
82 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8188 KB Output is correct
2 Correct 17 ms 8120 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 37 ms 8096 KB Output is correct
5 Correct 192 ms 8144 KB Output is correct
6 Correct 212 ms 8080 KB Output is correct
7 Correct 189 ms 8152 KB Output is correct
8 Correct 244 ms 8040 KB Output is correct
9 Correct 182 ms 8132 KB Output is correct
10 Correct 227 ms 8028 KB Output is correct
11 Correct 158 ms 8080 KB Output is correct
12 Correct 10 ms 8120 KB Output is correct
13 Correct 14 ms 8096 KB Output is correct
14 Correct 8 ms 8120 KB Output is correct
15 Correct 34 ms 8120 KB Output is correct
16 Correct 197 ms 8080 KB Output is correct
17 Correct 205 ms 8108 KB Output is correct
18 Correct 239 ms 8108 KB Output is correct
19 Correct 196 ms 8116 KB Output is correct
20 Correct 181 ms 8112 KB Output is correct
21 Correct 163 ms 8112 KB Output is correct
22 Correct 171 ms 8112 KB Output is correct
23 Correct 492 ms 8080 KB Output is correct
24 Correct 412 ms 8112 KB Output is correct
25 Correct 412 ms 8068 KB Output is correct
26 Incorrect 452 ms 8080 KB Output isn't correct
27 Halted 0 ms 0 KB -