# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548729 | krit3379 | Bootfall (IZhO17_bootfall) | C++17 | 1087 ms | 16076 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define N 250005
int a[505],odd,even,ma,sum,s;
bool dp[505][N],flag;
vector<int> ans;
int main(){
int n,i,j,k;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i],(a[i]%2)?odd++:even++,ma=max(ma,a[i]),dp[i][0]=true;
dp[0][0]=true;
for(i=1;i<=n;i++){
for(j=N-1;j>=a[i];j--){
for(k=1;k<=n;k++){
if(i==k)continue;
dp[k][j]|=dp[k][j-a[i]];
}
dp[0][j]|=dp[0][j-a[i]];
}
}
if((odd&&even)||(odd&&n%2)||!dp[0][sum/2]){printf("0");return 0;}
for(i=odd?1:2;i<=sum-ma;i+=2){
flag=true;
for(j=1;j<=n&&flag;j++){
s=(sum-a[j]+i)/2;
if(s-i<0||!dp[j][s-i])flag=false;
}
if(flag)ans.push_back(i);
}
printf("%d\n",ans.size());
for(auto x:ans)printf("%d ",x);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |