제출 #1045798

#제출 시각아이디문제언어결과실행 시간메모리
1045798hirayuu_ojUplifting Excursion (BOI22_vault)C++17
20 / 100
1162 ms15260 KiB
#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];
    }
    if(L<0) {
        L=-L;
        rep(i,M) {
            swap(A[i],A[M*2-i]);
        }
    }
    const ll mx=600000;
    vector<ll> dp(mx+1,-(1LL<<60));
    dp[0]=0;
    for(ll i=M; i>0; i--) {
        vector<ll> ndp(mx+1,-(1LL<<60));
        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[k]-cnt) {
                    deq.pop_front();
                }
                deq.push_front({dp[k]-cnt,cnt});
                if(deq.back().second<cnt-A[M+i])deq.pop_back();
                ndp[k]=deq.back().first+cnt;
                cnt++;
            }
        }
        swap(dp,ndp);
    }
    vector<ll> dp2(mx+1,-(1LL<<60));
    dp2[0]=0;
    for(ll i=M; i>0; i--) {
        vector<ll> ndp(mx+1,-(1LL<<60));
        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<=dp2[k]-cnt) {
                    deq.pop_front();
                }
                deq.push_front({dp2[k]-cnt,cnt});
                if(deq.back().second<cnt-A[M-i])deq.pop_back();
                ndp[k]=deq.back().first+cnt;
                cnt++;
            }
        }
        swap(dp2,ndp);
    }
    ll ans=-(1LL<<60);
    rng(i,L,mx) {
        ans=max(ans,dp[i]+dp2[i-L]+A[M]);
    }
    if(ans<0)cout<<"impossible\n";
    else cout<<ans<<"\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...