Submission #1074839

#TimeUsernameProblemLanguageResultExecution timeMemory
1074839huutuanUplifting Excursion (BOI22_vault)C++14
90 / 100
5073 ms11748 KiB
#include <bits/stdc++.h> using namespace std; using ll=long long; // #define int long long const int M=310; const ll inf=3e18; int m; ll L, a[M*2]; void impossible(){ cout << "impossible\n"; exit(0); } ll tl, tr; vector<ll> f; void dp(ll power2, vector<pair<ll, ll>> v){ ll szl=max(0ll, min(m*m*2ll, (tl-(-inf))/power2)); ll szr=max(0ll, min(m*m*2ll, (inf-tr)/power2)); tl-=szl*power2, tr+=szr*power2; reverse(f.begin(), f.end()); f.resize((int)f.size()+szl, -1); reverse(f.begin(), f.end()); f.resize((int)f.size()+szr, -1); for (auto &i:v){ ll val=i.first, cnt=i.second; if (val>0){ for (int j=(int)f.size()-1; j>=val; --j){ if (f[j-val]!=-1) f[j]=max(f[j], f[j-val]+cnt); } }else{ for (int j=0; j-val<(int)f.size(); ++j){ if (f[j-val]!=-1) f[j]=max(f[j], f[j-val]+cnt); } } } reverse(f.begin(), f.end()); while (f.size() && f.back()==-1){ tl+=power2; f.pop_back(); } reverse(f.begin(), f.end()); while (f.size() && f.back()==-1){ tr-=power2; f.pop_back(); } if (f.empty()) impossible(); return; } vector<pair<ll, ll>> v[50]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> m >> L; for (int i=-m; i<=m; ++i) cin >> a[m+i]; for (int i=-m; i<=m; ++i) if (i){ ll val=i, cnt=0; while (val%2==0) val/=2, ++cnt; for (int j=0; j<50; ++j) if (a[m+i]>=(1ll<<j)) v[j+cnt].emplace_back(val, 1ll<<j), a[m+i]-=1ll<<j; for (int j=0; j<50; ++j) if (a[m+i]>>j&1) v[j+cnt].emplace_back(val, 1ll<<j); } tl=0, tr=0, f={a[m]}; for (int i=0; i<50; ++i){ dp(1ll<<i, v[i]); if (abs(tl-L)>>i&1){ tl+=1ll<<i; if (f.empty()) impossible(); f.erase(f.begin()); } if (abs(tr-L)>>i&1){ tr-=1ll<<i; if (f.empty()) impossible(); f.pop_back(); } vector<ll> tmp; for (int j=0; j<(int)f.size(); j+=2) tmp.push_back(f[j]); tmp.swap(f); } if (tl>L || tr<L) impossible(); cout << f[(L-tl)>>50] << '\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...