# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36153 | minhtung0404 | Bootfall (IZhO17_bootfall) | C++14 | 453 ms | 4884 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>
const int N = 505;
using namespace std;
vector <int> dp, f, ck;
int n, sum, a[N], cnt;
int main(){
scanf("%d", &n);
for (int i = 1; i <= n; i++) {scanf("%d", &a[i]); sum += a[i];}
dp.assign(sum+1, 0); dp[0] = 1; sum = 0;
for (int i = 1; i <= n; i++) {sum += a[i]; for (int j = sum; j >= 0; j--) if (j >= a[i]) dp[j] += dp[j-a[i]];}
if (sum % 2 == 1 || dp[sum/2] == 0){
printf("0"); return 0;
}
f.assign(sum+1, 0); ck.assign(sum+1, 0);
for (int num = 1; num <= n; num++) {
for (int i = 0; i <= sum; i++){
f[i] = dp[i];
if (i >= a[num]) f[i] -= f[i-a[num]];
if (f[i] != 0 && 2*i+a[num]-sum >= 0) ck[2*i+a[num]-sum]++;
}
}
for (int i = 0; i <= sum; i++) if (ck[i] == n) cnt++;
printf("%d\n", cnt);
for (int i = 0; i <= sum; i++) if (ck[i] == n) printf("%d ", i);
}
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... |