Submission #319238

#TimeUsernameProblemLanguageResultExecution timeMemory
319238BeanZBootfall (IZhO17_bootfall)C++14
100 / 100
212 ms3300 KiB
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define task "A" #define ll int #define endl '\n' const int N = 505; const int mod = 1e9 + 7; ll a[N]; bool chk[505]; const int lim = 500 * 500 + 5; const int lim2 = 500 * 500 / 2 + 1; bitset<lim> bit2, tmp; ll sum = 0; void solve(ll l, ll r, bitset<lim> bit){ if (l == r){ tmp.reset(); for (int j = 0; j <= lim; j++){ if ((sum - j - a[l] - j) <= 0) break; if (bit[j] && ((sum - j - a[l] - j) > 0)){ tmp[sum - j - a[l] - j] = 1; } } bit2 = bit2 & tmp; return; } ll mid = (l + r) >> 1; bitset<lim> L, R; L = bit; R = bit; for (int i = mid + 1; i <= r; i++) R |= (R << a[i]); for (int i = l; i <= mid; i++) L |= (L << a[i]); solve(l, mid, R); solve(mid + 1, r, L); } bitset<lim> bit; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ll n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; bit[0] = 1; for (int i = 1; i <= n; i++){ bit |= (bit << a[i]); } if (bit[sum / 2] == 0) return cout << 0, 0; for (int i = 1; i < lim; i++) bit2[i] = 1; bit.reset(); bit[0] = 1; solve(1, n, bit); vector<ll> ans; for (int i = 1; i < lim; i++){ if (bit2[i]) ans.push_back(i); } cout << ans.size() << endl; for (auto j : ans) cout << j << " "; } /* 4 1 3 1 5 6 3 5 7 11 9 13 3 2 2 2 */

Compilation message (stderr)

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