답안 #580444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580444 2022-06-21T08:58:53 Z 반딧불(#8355) Uplifting Excursion (BOI22_vault) C++17
35 / 100
500 ms 8228 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]);
    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();
    frontCnt = accumulate(used+n, 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:120:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |     for(int i=0; i<=n+n; i++) scanf("%lld", &arr[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8120 KB Output is correct
2 Correct 15 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 43 ms 8092 KB Output is correct
5 Correct 248 ms 8112 KB Output is correct
6 Correct 208 ms 8084 KB Output is correct
7 Correct 259 ms 8080 KB Output is correct
8 Correct 232 ms 8104 KB Output is correct
9 Correct 238 ms 8112 KB Output is correct
10 Correct 237 ms 8080 KB Output is correct
11 Correct 249 ms 8108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8120 KB Output is correct
2 Correct 15 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 43 ms 8092 KB Output is correct
5 Correct 248 ms 8112 KB Output is correct
6 Correct 208 ms 8084 KB Output is correct
7 Correct 259 ms 8080 KB Output is correct
8 Correct 232 ms 8104 KB Output is correct
9 Correct 238 ms 8112 KB Output is correct
10 Correct 237 ms 8080 KB Output is correct
11 Correct 249 ms 8108 KB Output is correct
12 Correct 10 ms 8120 KB Output is correct
13 Correct 14 ms 8120 KB Output is correct
14 Correct 7 ms 8120 KB Output is correct
15 Correct 38 ms 8064 KB Output is correct
16 Correct 218 ms 8080 KB Output is correct
17 Correct 258 ms 8056 KB Output is correct
18 Correct 230 ms 8112 KB Output is correct
19 Correct 252 ms 8020 KB Output is correct
20 Correct 235 ms 8136 KB Output is correct
21 Correct 213 ms 8112 KB Output is correct
22 Correct 178 ms 8064 KB Output is correct
23 Correct 394 ms 8100 KB Output is correct
24 Incorrect 417 ms 8088 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 8120 KB Output is correct
2 Correct 121 ms 8112 KB Output is correct
3 Correct 119 ms 8124 KB Output is correct
4 Correct 136 ms 8088 KB Output is correct
5 Correct 111 ms 8108 KB Output is correct
6 Correct 112 ms 8112 KB Output is correct
7 Correct 108 ms 8088 KB Output is correct
8 Correct 123 ms 8080 KB Output is correct
9 Correct 130 ms 8088 KB Output is correct
10 Correct 98 ms 8076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 8120 KB Output is correct
2 Correct 121 ms 8112 KB Output is correct
3 Correct 119 ms 8124 KB Output is correct
4 Correct 136 ms 8088 KB Output is correct
5 Correct 111 ms 8108 KB Output is correct
6 Correct 112 ms 8112 KB Output is correct
7 Correct 108 ms 8088 KB Output is correct
8 Correct 123 ms 8080 KB Output is correct
9 Correct 130 ms 8088 KB Output is correct
10 Correct 98 ms 8076 KB Output is correct
11 Correct 13 ms 8032 KB Output is correct
12 Correct 17 ms 8108 KB Output is correct
13 Correct 8 ms 8120 KB Output is correct
14 Correct 36 ms 8076 KB Output is correct
15 Correct 139 ms 8080 KB Output is correct
16 Correct 94 ms 8080 KB Output is correct
17 Correct 109 ms 8024 KB Output is correct
18 Correct 132 ms 8112 KB Output is correct
19 Correct 110 ms 8084 KB Output is correct
20 Correct 114 ms 8040 KB Output is correct
21 Correct 110 ms 8112 KB Output is correct
22 Correct 101 ms 8080 KB Output is correct
23 Correct 104 ms 8112 KB Output is correct
24 Incorrect 152 ms 8228 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 8120 KB Output is correct
2 Correct 121 ms 8112 KB Output is correct
3 Correct 119 ms 8124 KB Output is correct
4 Correct 136 ms 8088 KB Output is correct
5 Correct 111 ms 8108 KB Output is correct
6 Correct 112 ms 8112 KB Output is correct
7 Correct 108 ms 8088 KB Output is correct
8 Correct 123 ms 8080 KB Output is correct
9 Correct 130 ms 8088 KB Output is correct
10 Correct 98 ms 8076 KB Output is correct
11 Correct 38 ms 8076 KB Output is correct
12 Correct 127 ms 8080 KB Output is correct
13 Correct 113 ms 8092 KB Output is correct
14 Correct 124 ms 8080 KB Output is correct
15 Correct 123 ms 8104 KB Output is correct
16 Correct 102 ms 8112 KB Output is correct
17 Correct 100 ms 8100 KB Output is correct
18 Correct 115 ms 8088 KB Output is correct
19 Correct 113 ms 8064 KB Output is correct
20 Correct 123 ms 8032 KB Output is correct
21 Correct 164 ms 8036 KB Output is correct
22 Correct 210 ms 8112 KB Output is correct
23 Correct 204 ms 8088 KB Output is correct
24 Correct 227 ms 8104 KB Output is correct
25 Correct 200 ms 8084 KB Output is correct
26 Correct 199 ms 8164 KB Output is correct
27 Correct 170 ms 8212 KB Output is correct
28 Correct 229 ms 8112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8120 KB Output is correct
2 Correct 15 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 43 ms 8092 KB Output is correct
5 Correct 248 ms 8112 KB Output is correct
6 Correct 208 ms 8084 KB Output is correct
7 Correct 259 ms 8080 KB Output is correct
8 Correct 232 ms 8104 KB Output is correct
9 Correct 238 ms 8112 KB Output is correct
10 Correct 237 ms 8080 KB Output is correct
11 Correct 249 ms 8108 KB Output is correct
12 Correct 35 ms 8120 KB Output is correct
13 Correct 121 ms 8112 KB Output is correct
14 Correct 119 ms 8124 KB Output is correct
15 Correct 136 ms 8088 KB Output is correct
16 Correct 111 ms 8108 KB Output is correct
17 Correct 112 ms 8112 KB Output is correct
18 Correct 108 ms 8088 KB Output is correct
19 Correct 123 ms 8080 KB Output is correct
20 Correct 130 ms 8088 KB Output is correct
21 Correct 98 ms 8076 KB Output is correct
22 Correct 13 ms 8032 KB Output is correct
23 Correct 17 ms 8108 KB Output is correct
24 Correct 8 ms 8120 KB Output is correct
25 Correct 36 ms 8076 KB Output is correct
26 Correct 139 ms 8080 KB Output is correct
27 Correct 94 ms 8080 KB Output is correct
28 Correct 109 ms 8024 KB Output is correct
29 Correct 132 ms 8112 KB Output is correct
30 Correct 110 ms 8084 KB Output is correct
31 Correct 114 ms 8040 KB Output is correct
32 Correct 110 ms 8112 KB Output is correct
33 Correct 101 ms 8080 KB Output is correct
34 Correct 104 ms 8112 KB Output is correct
35 Incorrect 152 ms 8228 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 8120 KB Output is correct
2 Correct 121 ms 8112 KB Output is correct
3 Correct 119 ms 8124 KB Output is correct
4 Correct 136 ms 8088 KB Output is correct
5 Correct 111 ms 8108 KB Output is correct
6 Correct 112 ms 8112 KB Output is correct
7 Correct 108 ms 8088 KB Output is correct
8 Correct 123 ms 8080 KB Output is correct
9 Correct 130 ms 8088 KB Output is correct
10 Correct 98 ms 8076 KB Output is correct
11 Correct 38 ms 8076 KB Output is correct
12 Correct 127 ms 8080 KB Output is correct
13 Correct 113 ms 8092 KB Output is correct
14 Correct 124 ms 8080 KB Output is correct
15 Correct 123 ms 8104 KB Output is correct
16 Correct 102 ms 8112 KB Output is correct
17 Correct 100 ms 8100 KB Output is correct
18 Correct 115 ms 8088 KB Output is correct
19 Correct 113 ms 8064 KB Output is correct
20 Correct 123 ms 8032 KB Output is correct
21 Correct 164 ms 8036 KB Output is correct
22 Correct 210 ms 8112 KB Output is correct
23 Correct 204 ms 8088 KB Output is correct
24 Correct 227 ms 8104 KB Output is correct
25 Correct 200 ms 8084 KB Output is correct
26 Correct 199 ms 8164 KB Output is correct
27 Correct 170 ms 8212 KB Output is correct
28 Correct 229 ms 8112 KB Output is correct
29 Correct 37 ms 8184 KB Output is correct
30 Correct 120 ms 8080 KB Output is correct
31 Correct 130 ms 8012 KB Output is correct
32 Correct 153 ms 8132 KB Output is correct
33 Correct 123 ms 8084 KB Output is correct
34 Correct 114 ms 8092 KB Output is correct
35 Correct 93 ms 8120 KB Output is correct
36 Correct 100 ms 8112 KB Output is correct
37 Correct 124 ms 8092 KB Output is correct
38 Correct 104 ms 8080 KB Output is correct
39 Correct 166 ms 8128 KB Output is correct
40 Correct 244 ms 8084 KB Output is correct
41 Correct 178 ms 8112 KB Output is correct
42 Correct 188 ms 8168 KB Output is correct
43 Correct 243 ms 8076 KB Output is correct
44 Correct 211 ms 8124 KB Output is correct
45 Correct 173 ms 8192 KB Output is correct
46 Correct 254 ms 8016 KB Output is correct
47 Correct 381 ms 8020 KB Output is correct
48 Correct 431 ms 8084 KB Output is correct
49 Correct 378 ms 8072 KB Output is correct
50 Correct 341 ms 8088 KB Output is correct
51 Correct 354 ms 8072 KB Output is correct
52 Correct 394 ms 8084 KB Output is correct
53 Correct 366 ms 8080 KB Output is correct
54 Correct 406 ms 8204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8120 KB Output is correct
2 Correct 15 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 43 ms 8092 KB Output is correct
5 Correct 248 ms 8112 KB Output is correct
6 Correct 208 ms 8084 KB Output is correct
7 Correct 259 ms 8080 KB Output is correct
8 Correct 232 ms 8104 KB Output is correct
9 Correct 238 ms 8112 KB Output is correct
10 Correct 237 ms 8080 KB Output is correct
11 Correct 249 ms 8108 KB Output is correct
12 Correct 10 ms 8120 KB Output is correct
13 Correct 14 ms 8120 KB Output is correct
14 Correct 7 ms 8120 KB Output is correct
15 Correct 38 ms 8064 KB Output is correct
16 Correct 218 ms 8080 KB Output is correct
17 Correct 258 ms 8056 KB Output is correct
18 Correct 230 ms 8112 KB Output is correct
19 Correct 252 ms 8020 KB Output is correct
20 Correct 235 ms 8136 KB Output is correct
21 Correct 213 ms 8112 KB Output is correct
22 Correct 178 ms 8064 KB Output is correct
23 Correct 394 ms 8100 KB Output is correct
24 Incorrect 417 ms 8088 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 8120 KB Output is correct
2 Correct 121 ms 8112 KB Output is correct
3 Correct 119 ms 8124 KB Output is correct
4 Correct 136 ms 8088 KB Output is correct
5 Correct 111 ms 8108 KB Output is correct
6 Correct 112 ms 8112 KB Output is correct
7 Correct 108 ms 8088 KB Output is correct
8 Correct 123 ms 8080 KB Output is correct
9 Correct 130 ms 8088 KB Output is correct
10 Correct 98 ms 8076 KB Output is correct
11 Correct 38 ms 8076 KB Output is correct
12 Correct 127 ms 8080 KB Output is correct
13 Correct 113 ms 8092 KB Output is correct
14 Correct 124 ms 8080 KB Output is correct
15 Correct 123 ms 8104 KB Output is correct
16 Correct 102 ms 8112 KB Output is correct
17 Correct 100 ms 8100 KB Output is correct
18 Correct 115 ms 8088 KB Output is correct
19 Correct 113 ms 8064 KB Output is correct
20 Correct 123 ms 8032 KB Output is correct
21 Correct 164 ms 8036 KB Output is correct
22 Correct 210 ms 8112 KB Output is correct
23 Correct 204 ms 8088 KB Output is correct
24 Correct 227 ms 8104 KB Output is correct
25 Correct 200 ms 8084 KB Output is correct
26 Correct 199 ms 8164 KB Output is correct
27 Correct 170 ms 8212 KB Output is correct
28 Correct 229 ms 8112 KB Output is correct
29 Correct 37 ms 8184 KB Output is correct
30 Correct 120 ms 8080 KB Output is correct
31 Correct 130 ms 8012 KB Output is correct
32 Correct 153 ms 8132 KB Output is correct
33 Correct 123 ms 8084 KB Output is correct
34 Correct 114 ms 8092 KB Output is correct
35 Correct 93 ms 8120 KB Output is correct
36 Correct 100 ms 8112 KB Output is correct
37 Correct 124 ms 8092 KB Output is correct
38 Correct 104 ms 8080 KB Output is correct
39 Correct 166 ms 8128 KB Output is correct
40 Correct 244 ms 8084 KB Output is correct
41 Correct 178 ms 8112 KB Output is correct
42 Correct 188 ms 8168 KB Output is correct
43 Correct 243 ms 8076 KB Output is correct
44 Correct 211 ms 8124 KB Output is correct
45 Correct 173 ms 8192 KB Output is correct
46 Correct 254 ms 8016 KB Output is correct
47 Correct 381 ms 8020 KB Output is correct
48 Correct 431 ms 8084 KB Output is correct
49 Correct 378 ms 8072 KB Output is correct
50 Correct 341 ms 8088 KB Output is correct
51 Correct 354 ms 8072 KB Output is correct
52 Correct 394 ms 8084 KB Output is correct
53 Correct 366 ms 8080 KB Output is correct
54 Correct 406 ms 8204 KB Output is correct
55 Correct 36 ms 8112 KB Output is correct
56 Correct 131 ms 8044 KB Output is correct
57 Correct 96 ms 8132 KB Output is correct
58 Correct 102 ms 8084 KB Output is correct
59 Correct 127 ms 8080 KB Output is correct
60 Correct 107 ms 8056 KB Output is correct
61 Correct 99 ms 8080 KB Output is correct
62 Correct 104 ms 8200 KB Output is correct
63 Correct 149 ms 8096 KB Output is correct
64 Correct 112 ms 8088 KB Output is correct
65 Correct 166 ms 8120 KB Output is correct
66 Correct 162 ms 8080 KB Output is correct
67 Correct 211 ms 8112 KB Output is correct
68 Correct 205 ms 8076 KB Output is correct
69 Correct 206 ms 8184 KB Output is correct
70 Correct 250 ms 8124 KB Output is correct
71 Correct 174 ms 8072 KB Output is correct
72 Correct 191 ms 8120 KB Output is correct
73 Correct 352 ms 8084 KB Output is correct
74 Correct 347 ms 8112 KB Output is correct
75 Correct 395 ms 8068 KB Output is correct
76 Correct 362 ms 8088 KB Output is correct
77 Correct 473 ms 8076 KB Output is correct
78 Correct 416 ms 8076 KB Output is correct
79 Correct 367 ms 8084 KB Output is correct
80 Correct 500 ms 8084 KB Output is correct
81 Runtime error 3 ms 468 KB Execution killed with signal 11
82 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8120 KB Output is correct
2 Correct 15 ms 8120 KB Output is correct
3 Correct 7 ms 8120 KB Output is correct
4 Correct 43 ms 8092 KB Output is correct
5 Correct 248 ms 8112 KB Output is correct
6 Correct 208 ms 8084 KB Output is correct
7 Correct 259 ms 8080 KB Output is correct
8 Correct 232 ms 8104 KB Output is correct
9 Correct 238 ms 8112 KB Output is correct
10 Correct 237 ms 8080 KB Output is correct
11 Correct 249 ms 8108 KB Output is correct
12 Correct 10 ms 8120 KB Output is correct
13 Correct 14 ms 8120 KB Output is correct
14 Correct 7 ms 8120 KB Output is correct
15 Correct 38 ms 8064 KB Output is correct
16 Correct 218 ms 8080 KB Output is correct
17 Correct 258 ms 8056 KB Output is correct
18 Correct 230 ms 8112 KB Output is correct
19 Correct 252 ms 8020 KB Output is correct
20 Correct 235 ms 8136 KB Output is correct
21 Correct 213 ms 8112 KB Output is correct
22 Correct 178 ms 8064 KB Output is correct
23 Correct 394 ms 8100 KB Output is correct
24 Incorrect 417 ms 8088 KB Output isn't correct
25 Halted 0 ms 0 KB -