Submission #953863

#TimeUsernameProblemLanguageResultExecution timeMemory
953863PM1Uplifting Excursion (BOI22_vault)C++17
100 / 100
1357 ms3664 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fr first #define sc second const ll mxn=305; ll m,a[mxn*2],l,sum,ans,num; vector<pair<ll,ll>>v; ll dp[2][mxn*mxn*2]; void add(ll tedad,ll x,ll z){ tedad=(min(tedad,2*m)); for(ll i=1;i<=tedad;i*=2){ v.push_back({i*x,z*i}); tedad-=i; } if(tedad>0) v.push_back({tedad*x,z*tedad}); } void solve(){ for(ll i=m;i>=0;i--){ ans+=a[i]; num+=a[i]*(i-m); add(a[i],-(i-m),-1); } ll i=m+1; for(;i<m*2+1;i++){ if(num>l)break; if(num+a[i]*(i-m)<=l){ ans+=a[i]; num+=a[i]*(i-m); add(a[i],-(i-m),-1); continue; } ll x=l-num; x=x/(i-m); x=min(x,a[i]); num+=(i-m)*x; ans+=x; add(x,-(i-m),-1); add(a[i]-x,i-m,1); i++; break; } for(;i<m*2+1;i++){ add(a[i],(i-m),1); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>m>>l; ll hh=0,hhh=0; for(ll i=0;i<m*2+1;i++){ cin>>a[i]; sum+=(i-m)*a[i]; if(i-m>0)hh+=(i-m)*a[i]; else hhh+=(i-m)*a[i]; } if(l>hh || l<hhh){ cout<<"impossible"; return 0; } if(sum<l){ for(int i=1;i<=m;i++) swap(a[i+m],a[m-i]); l*=-1; sum*=-1; } solve(); for(ll i=0;i<=2*m*m;i++)dp[1][i]=-1e18; dp[1][m*m]=0; for(ll i=0;i<v.size();i++){ ll x=v[i].fr,y=v[i].sc; ll z=i&1; for(ll j=0;j<=2*m*m;j++){ if(j-x>=0 && j-x<=2*m*m && dp[z^1][j-x]!=-1e18) dp[z][j]=max(dp[z^1][j],dp[z^1][j-x]+y); else dp[z][j]=dp[z^1][j]; } } ll x=v.size()&1; x^=1; l-=num; if( l>m*m || l<-m*m ||dp[x][l+m*m]==-1e18 || ans+dp[x][l+m*m]<0){ cout<<"impossible"; return 0; } cout<<ans+dp[x][l+m*m]; return 0; }

Compilation message (stderr)

vault.cpp: In function 'int main()':
vault.cpp:75:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for(ll i=0;i<v.size();i++){
      |             ~^~~~~~~~~
#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...