Submission #1077413

#TimeUsernameProblemLanguageResultExecution timeMemory
1077413wangziyanmoUplifting Excursion (BOI22_vault)C++14
20 / 100
1569 ms8384 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int dp[3000010]; int a[10000],w[10000]; int siz; signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,q;cin>>n>>q; for (int i=-n;i<=n;i++){ int k;cin>>k; int num=1; while (k>=num){ k-=num; a[++siz]=num*i; w[siz]=num; num<<=1; } if (k>0){ a[++siz]=k*i; w[siz]=k; } } //for (int i=1;i<=siz;i++) cout<<a[i]<<' '<<w[i]<<"\n"; for (int i=0;i<=1010000;i++) dp[i]=-1e18; dp[505000]=0; for (int i=1;i<=siz;i++){ if (a[i]<0){ for (int j=0;j<=1010000;j++){ if (j-a[i]>=0 && j-a[i]<=1010000 && dp[j-a[i]]!=-1e18){ dp[j]=max(dp[j],dp[j-a[i]]+w[i]); } } continue; } for (int j=1010000;j>=0;j--){ if (j-a[i]>=0 && j-a[i]<=1010000 && dp[j-a[i]]!=-1e18){ dp[j]=max(dp[j],dp[j-a[i]]+w[i]); } } } if (q>505000 || q<-505000 || dp[505000+q]==-1e18) cout<<"impossible\n"; else cout<<dp[505000+q]<<"\n"; }
#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...