답안 #937090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
937090 2024-03-03T13:10:04 Z berr Uplifting Excursion (BOI22_vault) C++17
0 / 100
1 ms 456 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m; cin >> n >> m;
    vector<int> a(n*2+1);
    int sum=0, el = 0, top=0;

    for(int i=-1*n; i<=n; i++){
        cin >> a[i+n];
        sum+=i*a[i+n]; el+=a[i+n];
    }

    m = sum-m;
    vector<int> used(n*2+1);
    int hedef;

    if(m<0){
        int sum=0;
        for(int i=-n; i<0; i++){
            if(sum+a[i+n]*i > m){
                used[i+n]=a[i+n];
                sum+=a[i+n]*i;
                top+=a[i+n];
                a[i+n]=0;
            }
            else if(sum > m){
                int s=0;
                for(int l=50; l>=0; l--){
                    int tmp = s+(1LL<<l);
                    if(tmp > a[i+n]) continue;
                    if(tmp*i+sum > m){
                        s=tmp;
                    }
                }
                s++;
                sum+=s*i;
                top+=s;
                used[i+n] =s;
                a[i+n]-=n;
            }
        }

        if(sum>m){
            cout<<"impossible";
            return 0;
        }
        else hedef = m-sum;
    }
    else{
        int sum=0;
        for(int i=n; i>=0; i--){
            if(sum+a[i+n]*i < m){
                used[i+n]=a[i+n];
                sum+=a[i+n]*i;
                top+=a[i+n];
                a[i+n]=0;
            }
            else if(sum < m){
                int s=0;
                for(int l=50; l>=0; l--){
                    int tmp = s+(1LL<<l);
                    if(tmp > a[i+n]) continue;
                    if(tmp*i+sum < m){
                        s=tmp;
                    }
                }
                s++;
                top+=s;
                sum+=s*i;
                used[i+n] =s;
                a[i+n]-=n;
            }
        }

        if(sum<m){
            cout<<"impossible";
            return 0;
        }
        else hedef = m-sum;
    }

    vector<int> vis1(n*2+1), val(n*2+1, 1e18);


    val[n]=0;

    int mi=0;
    int pf=1;
    int h=50;
    while(pf&&h--){
        int flag = 0;
        for(int i=-n; i<=n&&!flag; i++){
            if(used[i+n]>0){
                for(int l=-n; l<=n; l++){
                    if(l-i>=-n&&l-i<=n)
                    if(val[l+n]==mi && val[(l-i)+n] >mi){
                        flag = 1;
                        val[(l-i+n)]=mi-1;
                    }
                }

                if(flag){
                    used[i+n]--; mi--;
                }
            }
        }
        if(!flag){
            int check = 0;
            for(int i=-n; i<=n; i++){
                int check2=0;
                if(a[i+n]>0){
                    for(int l=-n; l<=n; l++){
                        if(l+i>=-n && l+i<=n){
                            if(val[l+n]==mi && val[(l+i)+n]==1e18){
                                check2 = 1;
                                val[(l+i)+n] = mi+1;
                            }
                        }
                    }

                    if(check2) a[i+n]--, check=1;
                }
            }
            if(check) mi++;
            else pf = 0;
        }
    }
    
    if(val[hedef+n]!=1e18){
        cout<<el-(top+val[hedef+n]);
    }   
    else cout<<"impossible";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -