Submission #36961

#TimeUsernameProblemLanguageResultExecution timeMemory
36961nickyrioBootfall (IZhO17_bootfall)C++14
100 / 100
719 ms10088 KiB
#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], newDp[N * N], cnt[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] = 1;
    FOR(i, 1, n) {
        total += a[i];
        FORD(S, all, a[i]) {
            if (dp[S - a[i]]) {
                dp[S] += dp[S - a[i]];
            }
        }
    }
    if (all % 2 == 1 || dp[all / 2] == 0) {
        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) newDp[S] = dp[S];
        FOR(S, a[i], all) newDp[S] -= newDp[S - a[i]];
        FOR(value, 1, all) {
            if ((all + value - a[i]) % 2 == 1 || all - a[i] < value) {
                continue;
            }
            int newMid = (all - a[i] + value) / 2;
            if (newDp[newMid - value] == 0) {
                continue;
            }
            cnt[value]++;
        }
    }
    FOR(value, 1, all) {
        if (cnt[value] == n) {
            res.push_back(value);
        }
    }
    printf("%d\n", res.size());
    for (int value : res) printf("%d ", value);
}

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:57: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 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...