Submission #36959

#TimeUsernameProblemLanguageResultExecution timeMemory
36959nickyrioBootfall (IZhO17_bootfall)C++14
0 / 100
0 ms1840 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 * 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 (stderr)

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 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...