Submission #1126569

#TimeUsernameProblemLanguageResultExecution timeMemory
1126569GrayBootfall (IZhO17_bootfall)C++20
65 / 100
1014 ms38864 KiB
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define ff first #define ss second #define ln "\n" #define mp make_pair const ll MOD = 1e9+7; const ll INF = 2e18; struct SparseTable{ vector<vector<ll>> t; ll n; vector<ll> log; ll func(ll a, ll b){ return min(a, b); } void init(ll N, vector<ll> &a){ n=N; log.resize(n+1); for (ll i=2; i<=n; i++) log[i]=log[i/2]+1; t.resize(log[N]+1, vector<ll>(n)); t[0]=a; for (ll i=1; i<=log[n]; i++){ for (ll j=0; j<=n-(1<<i); j++){ t[i][j]=func(t[i-1][j], t[i-1][j+(1<<(i-1))]); } } } ll query(ll l, ll r){ ll lg = log[r-l+1]; return func(t[lg][l], t[lg][r-(1<<lg)+1]); } }; void solve(){ ll n; cin >> n; vector<ll> a(n); bitset<500*600> dp; ll sm=0; for (ll i=0; i<n; i++){ cin >> a[i]; sm+=a[i]; dp = (dp<<a[i])|dp; dp.set(a[i]); } if (!(dp[sm/2] and sm%2==0)){ cout << 0 << ln; return; } bitset<500*600> pos; for (ll i=1; i<=250000; i++) pos.set(i); vector<bitset<500*600>> pref(n), suff(n); pref[0].set(0); suff[n-1]=pref[0]; for (ll i=0; i<n; i++){ if (i) pref[i]|=pref[i-1]; pref[i] = (pref[i]<<a[i])|pref[i]; pref[i].set(a[i]); } for (ll i=n-1; i>=0; i--){ if (i!=n-1) suff[i]|=suff[i+1]; suff[i] = (suff[i]<<a[i])|suff[i]; suff[i].set(a[i]); } for (ll i=0; i<n; i++){ dp.reset(); dp.set(0); ll sum=0; for (ll j=0; j<n; j++){ if (i==j) continue; sum+=a[j]; } if (i<n/2){ dp = suff[i+1]; for (ll j=0; j<i; j++) { dp=(dp<<a[j])|dp; dp.set(a[j]); } }else{ if (i-1>=0) dp = pref[i-1]; for (ll j=n-1; j>i; j--){ dp = (dp<<a[j])|dp; dp.set(a[j]); } } // cout << i << ": "; for (ll j=1; j<=250000; j++){ if ((sum-j)%2 or sum<j or !dp[(sum-j)/2]) { pos.reset(j); // if (j==600) cout << sum-j << " - " << (!dp[(sum-j)/2]) << ln; } } // cout << ln; } vector<ll> res; for (ll i=1; i<=250000; i++){ if (pos[i]) res.push_back(i); } cout << res.size() << ln; for (auto ch:res) cout << ch << " "; cout << ln; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); auto start = chrono::high_resolution_clock::now(); ll t=1; // cin >> t; while (t--) solve(); #ifdef LOCAL auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start); cout << setprecision(0) << fixed << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl; #endif }
#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...