Submission #1128106

#TimeUsernameProblemLanguageResultExecution timeMemory
1128106farni4kBootfall (IZhO17_bootfall)C++20
13 / 100
1095 ms824 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N=125002; int a[505]; bool dp[505][N]; bool can(int n=500, int sum=0) { int nd=sum/2; for (int i = 1; i<=n; i++) { for (int j = 0; j<=nd; j++) dp[i][j]=0; } dp[0][0]=1; if (sum%2==0) { for (int i = 1; i<=n; i++) { for (int j = 0; j<=nd; j++) { if (a[i-1]<=j) dp[i][j]=(dp[i-1][j] || dp[i-1][j-a[i-1]]); else dp[i][j]=dp[i-1][j]; } } if (dp[n][nd]) { return true; } } return false; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; int sum=0; for (int i = 0; i<n; i++) { cin>>a[i]; sum+=a[i]; } int hf=sum; if (can(n, sum)) { vector<int> ans; for (int i = 1; i<=hf; i++) { bool h=1; for (int j = 0; j<n; j++) { int dos=a[j]; sum-=a[j]; sum+=i; a[j]=i; if (!can(n,sum)) { h=0; sum=hf; a[j]=dos; break; } sum=hf; a[j]=dos; } if (h) ans.push_back(i); } cout<<ans.size()<<'\n'; for (int i = 0; i<ans.size(); i++) cout<<ans[i]<<' '; } else { cout<<"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...