Submission #36152

# Submission time Handle Problem Language Result Execution time Memory
36152 2017-12-06T04:36:26 Z minhtung0404 Bootfall (IZhO17_bootfall) C++14
0 / 100
0 ms 2016 KB
#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

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 time Memory Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Correct 0 ms 2016 KB Output is correct
3 Incorrect 0 ms 2016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Correct 0 ms 2016 KB Output is correct
3 Incorrect 0 ms 2016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Correct 0 ms 2016 KB Output is correct
3 Incorrect 0 ms 2016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Correct 0 ms 2016 KB Output is correct
3 Incorrect 0 ms 2016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Correct 0 ms 2016 KB Output is correct
3 Incorrect 0 ms 2016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Correct 0 ms 2016 KB Output is correct
3 Incorrect 0 ms 2016 KB Output isn't correct
4 Halted 0 ms 0 KB -