Submission #849637

#TimeUsernameProblemLanguageResultExecution timeMemory
849637vjudge1Bootfall (IZhO17_bootfall)C++17
100 / 100
254 ms3128 KiB
#include <bits/stdc++.h> #define TASK "esport" using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ll> ill; typedef pair<ll, int> lli; typedef pair<ll, ll> pll; const int MAX = 501; const int SQMAX = 250001; const int MOD = 1e9 + 7; int n, a[MAX]; int sum; ll dp[SQMAX]; bool possible[SQMAX]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; sum = accumulate(a + 1, a + n + 1, 0); dp[0] = 1; for (int i = 1; i <= n; ++i) for (int j = sum - a[i]; j >= 0; --j) dp[j + a[i]] += dp[j]; if (sum % 2 || !dp[sum / 2]) return cout << 0, 0; fill(possible + 1, possible + sum + 1, 1); for (int i = 1; i <= n; ++i) { for (int j = 0; j <= sum - a[i]; ++j) dp[j + a[i]] -= dp[j]; for (int cur = 1; cur <= sum; ++cur) { if ((sum - a[i] + cur) % 2) { possible[cur] = 0; continue; } int cur_req = (sum - a[i] + cur) / 2; if (cur_req <= sum && dp[cur_req]) continue; if (cur_req - cur >= 0 && cur_req - cur <= sum && dp[cur_req - cur]) continue; possible[cur] = 0; } for (int j = sum - a[i]; j >= 0; --j) dp[j + a[i]] += dp[j]; } cout << accumulate(possible, possible + sum + 1, 0) << '\n'; for (int i = 0; i <= sum; ++i) if (possible[i]) cout << i << ' '; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:29:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |                 freopen(TASK ".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:30:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |                 freopen(TASK ".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...