답안 #1045776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045776 2024-08-06T07:35:22 Z hirayuu_oj Uplifting Excursion (BOI22_vault) C++17
0 / 100
231 ms 258644 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define rng(i,l,r) for(ll i=(l); i<(r); i++)
#define all(x) x.begin(),x.end()
using ll=long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll M,L;
    cin>>M>>L;
    vector<ll> A(M*2+1);
    rep(i,M*2+1) {
        cin>>A[i];
    }
    const ll mx=1000000;
    vector<vector<ll>> dp(M+2,vector<ll>(mx+1,-(1LL<<60)));
    dp[M+1][0]=0;
    for(ll i=M; i>0; i--) {
        rep(j,i) {
            ll cnt=0;
            deque<pair<ll,ll>> deq;
            for(ll k=j; k<=mx; k+=i) {
                while(!deq.empty()&&deq.front().first<=dp[i+1][k]-cnt) {
                    deq.pop_front();
                }
                deq.push_front({dp[i+1][k]-cnt,cnt});
                if(deq.back().second<cnt-A[M+i])deq.pop_back();
                dp[i][k]=deq.back().first+cnt;
                cnt++;
            }
        }
    }
    if(L<0) {
        cout<<"impossible\n";
        return 0;
    }
    ll weight=L;
    ll used=A[M];
    ll ans=-(1LL<<60);
    rng(i,1,M+1) {
        ll skip=max(0LL,min(A[M+i],(L-mx+10)/i));
        weight-=skip*i;
        used+=skip;
        A[M+i]-=skip;
        rep(j,A[M+i]) {
            weight-=i;
            if(weight<0)break;
            used++;
            if(weight<=mx) {
                ans=max(ans,used+dp[i+1][weight]);
            }
        }
        if(weight<0)break;
    }
    if(ans<0) {
        cout<<"impossible\n";
    }
    else {
        cout<<ans<<"\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 39512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 39512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 102232 KB Output is correct
2 Incorrect 231 ms 258644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 102232 KB Output is correct
2 Incorrect 231 ms 258644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 102232 KB Output is correct
2 Incorrect 231 ms 258644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 39512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 102232 KB Output is correct
2 Incorrect 231 ms 258644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 39512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 102232 KB Output is correct
2 Incorrect 231 ms 258644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 39512 KB Output isn't correct
2 Halted 0 ms 0 KB -