답안 #580457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580457 2022-06-21T09:19:12 Z 반딧불(#8355) Uplifting Excursion (BOI22_vault) C++17
10 / 100
165 ms 8168 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);
    if(n>30) return 1;
    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:122:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |         scanf("%lld", &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8120 KB Output is correct
2 Correct 28 ms 8168 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 39 ms 8116 KB Output is correct
5 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8120 KB Output is correct
2 Correct 28 ms 8168 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 39 ms 8116 KB Output is correct
5 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8112 KB Output is correct
2 Correct 133 ms 8104 KB Output is correct
3 Correct 119 ms 8096 KB Output is correct
4 Correct 128 ms 8092 KB Output is correct
5 Correct 133 ms 8112 KB Output is correct
6 Correct 122 ms 8116 KB Output is correct
7 Correct 113 ms 8096 KB Output is correct
8 Correct 130 ms 8100 KB Output is correct
9 Correct 118 ms 8100 KB Output is correct
10 Correct 100 ms 8152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8112 KB Output is correct
2 Correct 133 ms 8104 KB Output is correct
3 Correct 119 ms 8096 KB Output is correct
4 Correct 128 ms 8092 KB Output is correct
5 Correct 133 ms 8112 KB Output is correct
6 Correct 122 ms 8116 KB Output is correct
7 Correct 113 ms 8096 KB Output is correct
8 Correct 130 ms 8100 KB Output is correct
9 Correct 118 ms 8100 KB Output is correct
10 Correct 100 ms 8152 KB Output is correct
11 Correct 10 ms 8120 KB Output is correct
12 Correct 14 ms 8088 KB Output is correct
13 Correct 8 ms 8120 KB Output is correct
14 Correct 38 ms 8120 KB Output is correct
15 Correct 164 ms 8052 KB Output is correct
16 Correct 109 ms 8096 KB Output is correct
17 Correct 137 ms 8052 KB Output is correct
18 Correct 165 ms 8096 KB Output is correct
19 Correct 144 ms 8104 KB Output is correct
20 Correct 107 ms 8064 KB Output is correct
21 Correct 118 ms 8096 KB Output is correct
22 Correct 109 ms 8112 KB Output is correct
23 Correct 133 ms 8092 KB Output is correct
24 Incorrect 149 ms 8116 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8112 KB Output is correct
2 Correct 133 ms 8104 KB Output is correct
3 Correct 119 ms 8096 KB Output is correct
4 Correct 128 ms 8092 KB Output is correct
5 Correct 133 ms 8112 KB Output is correct
6 Correct 122 ms 8116 KB Output is correct
7 Correct 113 ms 8096 KB Output is correct
8 Correct 130 ms 8100 KB Output is correct
9 Correct 118 ms 8100 KB Output is correct
10 Correct 100 ms 8152 KB Output is correct
11 Correct 41 ms 8120 KB Output is correct
12 Correct 102 ms 8096 KB Output is correct
13 Correct 91 ms 8112 KB Output is correct
14 Correct 110 ms 8100 KB Output is correct
15 Correct 111 ms 8052 KB Output is correct
16 Correct 104 ms 8032 KB Output is correct
17 Correct 93 ms 8056 KB Output is correct
18 Correct 114 ms 8080 KB Output is correct
19 Correct 99 ms 8052 KB Output is correct
20 Correct 97 ms 8072 KB Output is correct
21 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8120 KB Output is correct
2 Correct 28 ms 8168 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 39 ms 8116 KB Output is correct
5 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8112 KB Output is correct
2 Correct 133 ms 8104 KB Output is correct
3 Correct 119 ms 8096 KB Output is correct
4 Correct 128 ms 8092 KB Output is correct
5 Correct 133 ms 8112 KB Output is correct
6 Correct 122 ms 8116 KB Output is correct
7 Correct 113 ms 8096 KB Output is correct
8 Correct 130 ms 8100 KB Output is correct
9 Correct 118 ms 8100 KB Output is correct
10 Correct 100 ms 8152 KB Output is correct
11 Correct 41 ms 8120 KB Output is correct
12 Correct 102 ms 8096 KB Output is correct
13 Correct 91 ms 8112 KB Output is correct
14 Correct 110 ms 8100 KB Output is correct
15 Correct 111 ms 8052 KB Output is correct
16 Correct 104 ms 8032 KB Output is correct
17 Correct 93 ms 8056 KB Output is correct
18 Correct 114 ms 8080 KB Output is correct
19 Correct 99 ms 8052 KB Output is correct
20 Correct 97 ms 8072 KB Output is correct
21 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8120 KB Output is correct
2 Correct 28 ms 8168 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 39 ms 8116 KB Output is correct
5 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8112 KB Output is correct
2 Correct 133 ms 8104 KB Output is correct
3 Correct 119 ms 8096 KB Output is correct
4 Correct 128 ms 8092 KB Output is correct
5 Correct 133 ms 8112 KB Output is correct
6 Correct 122 ms 8116 KB Output is correct
7 Correct 113 ms 8096 KB Output is correct
8 Correct 130 ms 8100 KB Output is correct
9 Correct 118 ms 8100 KB Output is correct
10 Correct 100 ms 8152 KB Output is correct
11 Correct 41 ms 8120 KB Output is correct
12 Correct 102 ms 8096 KB Output is correct
13 Correct 91 ms 8112 KB Output is correct
14 Correct 110 ms 8100 KB Output is correct
15 Correct 111 ms 8052 KB Output is correct
16 Correct 104 ms 8032 KB Output is correct
17 Correct 93 ms 8056 KB Output is correct
18 Correct 114 ms 8080 KB Output is correct
19 Correct 99 ms 8052 KB Output is correct
20 Correct 97 ms 8072 KB Output is correct
21 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8120 KB Output is correct
2 Correct 28 ms 8168 KB Output is correct
3 Correct 8 ms 8120 KB Output is correct
4 Correct 39 ms 8116 KB Output is correct
5 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
6 Halted 0 ms 0 KB -