Submission #839815

#TimeUsernameProblemLanguageResultExecution timeMemory
839815nononoBootfall (IZhO17_bootfall)C++14
100 / 100
293 ms2756 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 505; int n, a[mxN]; int sum = 0; int dp[mxN * mxN]; bool good[mxN * mxN]; void add(int x) { sum += x; for(int i = sum; i >= x; i --) dp[i] += dp[i - x]; } void del(int x) { for(int i = x; i <= sum; i ++) dp[i] -= dp[i - x]; sum -= x; } signed main() { #define taskname "" if(fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); cin >> n; dp[0] = 1; for(int i = 1; i <= n; i ++) { cin >> a[i]; add(a[i]); } if(sum % 2 || !dp[sum / 2]) { return cout << 0, 0; } for(int i = 1; i <= sum; i ++) good[i] = true; for(int i = 1; i <= n; i ++) { del(a[i]); for(int j = 1; j <= sum + a[i]; j ++) { good[j] = (good[j] && (sum + j) % 2 == 0 && dp[(sum + j) / 2]); } add(a[i]); } vector<int> choose; for(int i = 1; i <= sum; i ++) if(good[i]) choose.push_back(i); cout << choose.size() << "\n"; for(int x : choose) cout << x << " "; return 0; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(taskname".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...