Submission #36959

# Submission time Handle Problem Language Result Execution time Memory
36959 2017-12-19T15:40:13 Z nickyrio Bootfall (IZhO17_bootfall) C++14
0 / 100
0 ms 1840 KB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i<= b; ++i)
#define FORD(i, a, b) for (int i = a; i>=b; --i)
#define REP(i, a) for (int i = 0; i<a; ++i)
#define N 555
#define pp pair<int, int>
#define bit(S, i) (((S) >> i) & 1)
#define IO cin.tie(NULL);cout.tie(NULL);
#define taskname "BOOTFALL"
using namespace std;

int n, a[N];
long long dp[N][N * N];
vector<int> res;

int main() {
 //   freopen(taskname".inp","r",stdin);
 //   freopen(taskname".out","w",stdout);
    IO;
    scanf("%d", &n);
    int all = 0;
    FOR(i, 1, n) scanf("%d", &a[i]);
    FOR(i, 1, n) all += a[i];
    int total = 0;
    dp[0][0] = 1;
    FOR(i, 1, n) {
        total += a[i];
        FORD(S, all, a[i]) {
            if (dp[0][S - a[i]]) {
                dp[0][S] += dp[0][S - a[i]];
            }
        }
    }
    if (all % 2 == 1) {
        printf("0");return 0;
    }
  //  FOR(S, 0, all) if (dp[0][S]) cerr << S << ':' << dp[0][S] << endl;
    FOR(i, 1, n) {
        FOR(S, 0, all) dp[i][S] = dp[0][S];
        FOR(S, a[i], all) dp[i][S] -= dp[i][S - a[i]];
    }
    FOR(value, 1, all) {
        if (dp[0][all / 2] == 0) continue;
        bool ok = true;
        FOR(i, 1, n) {
            if ((all + value - a[i]) % 2 == 1 || all - a[i] < value) {
                ok = false; break;
            }
            int newMid = (all - a[i] + value) / 2;
            if (dp[i][newMid - value] == 0) {
                ok = false; break;
            }
        }
        if (ok) {
            res.push_back(value);
        }
    }
    printf("%d\n", res.size());
    for (int value : res) printf("%d ", value);
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:58:30: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", res.size());
                              ^
bootfall.cpp:20:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
bootfall.cpp:22:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     FOR(i, 1, n) scanf("%d", &a[i]);
                                    ^
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -