Submission #340095

#TimeUsernameProblemLanguageResultExecution timeMemory
340095SprdaloBootfall (IZhO17_bootfall)C++17
65 / 100
1037 ms7144 KiB
#include <bits/stdc++.h> using namespace std; #define int ll typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<string> vs; typedef vector<pi> vp; typedef vector<pl> vpl; void no(){ cout << "0\n"; exit(0); } const int M = 250000; vi dp(M+510); signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int n; cin >> n; vi a(n); int suma = 0; bool pp = 0, np = 0; for (auto& i : a){ cin >> i; suma += i; if (i%2) np=1; else pp=1; } if ((pp && np) || suma%2) no(); dp[0]=1; for (int i = 0; i < n; ++i){ for (int j = M; j > -1; --j){ dp[a[i]+j] += dp[j]; } } if (!dp[suma/2]) no(); vi d(M+505, 0), cnt(M+505, 0), sol; for (int i = 0; i < n; ++i){ fill(d.begin(), d.end(), 0); for (int j = 0; j <= M; ++j){ d[j] += dp[j]; d[j+a[i]] -= d[j]; } for (int j = 0; j <= M; ++j){ if ((suma-a[i]+j)%2 == 0 && suma-a[i]-j>=0 && d[(suma-a[i]-j)/2]){ ++cnt[j]; if (cnt[j] == n) sol.push_back(j); } } } sort(sol.begin(), sol.end()); cout << (int)sol.size() << '\n'; for (auto& i : sol) cout << i << ' '; }
#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...