Submission #36153

#TimeUsernameProblemLanguageResultExecution timeMemory
36153minhtung0404Bootfall (IZhO17_bootfall)C++14
100 / 100
453 ms4884 KiB
#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)

bootfall.cpp: In function 'int main()':
bootfall.cpp:9:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
bootfall.cpp:10:53: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; i++) {scanf("%d", &a[i]); sum += a[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...