Submission #1175924

#TimeUsernameProblemLanguageResultExecution timeMemory
1175924HaanhtienBootfall (IZhO17_bootfall)C++17
13 / 100
1 ms328 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for(int i=(a), _b=(b); i<=_b; i++) #define FORD(i, a, b) for(int i=(a), _b=(b); i>=_b; i--) #define BIT(i, j) ((i>>j)&1) #define pb push_back #define ii pair<ll, ll> #define pii pair<ll, ii> #define all(x) x.begin(), x.end() #define fi first #define se second const ll inf = 1e18; const ll mod = 1e9+7; const ll N = 505; const ll M = 50005; ll n, a[N], ans, sum, bit[N * N], f[N * N], res[N * N]; void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } ll half = sum/2; f[0] = 1; for (int i = 1; i <= n; i++) { for (int j = sum; j >= a[i]; j--) { f[j] += f[j - a[i]]; } } if (sum % 2 != 0 || f[sum/2] == 0) { cout << 0; return; } fill(res, res + sum + 1, 1); for (int i = 1; i <= n; i++) { ll tmp = sum - a[i]; fill(bit, bit + sum + 1, 0); for (int j = a[i]; j <= sum; j++) { f[j] -= f[j - a[i]]; } for (int A = 1; A <= sum; A++) { if (f[A] > 0) { ll B = tmp - A; ll x = abs(A - B); bit[x] = 1; } } for (int k = 1; k <= sum; k++) res[k] &= bit[k]; for (int j = sum; j >= a[i]; j--) { f[j] += f[j - a[i]]; } } vector<int> v; for (int i = 1; i <= sum; i++) { if (res[i]) v.pb(i); } cout << v.size() << '\n'; for (auto i : v) cout <<i << ' '; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "task" if(fopen(task".inp", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } if(fopen("task.inp", "r")) { freopen("task.INP", "r", stdin); freopen("task.OUT", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen("task.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         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...