This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
#include<bits/stdc++.h>
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"
using namespace std;
using pii = pair<int, int>;
const int N = (int)5e2 + 7; // make sure this is right
const int M = N * N;
const int inf = (int)1e9;
const ll INF = (ll)3e18 + 7;
const ll MOD = (ll)1e18 + 7; // make sure this is right
pii dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int n, a[N];
ll dp[M], cnt[M];
ll sum(ll x, ll y) {
x += y;
if(x >= MOD) x -= MOD;
return x;
}
ll sub(ll x, ll y) {
x -= y;
if(x < 0) x += MOD;
return x;
}
void add(int x) {
for(int i = M - 1; i >= x; --i) {
dp[i] = sum(dp[i], dp[i - x]);
}
}
void del(int x) {
for(int i = x; i < M; ++i) {
dp[i] = sub(dp[i], dp[i - x]);
}
}
void solve() {
cin >> n;
dp[0] = 1;
int sum = 0;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
add(a[i]);
sum += a[i];
}
if((sum & 1) || !dp[sum / 2]) {
cout << "0\n";
return;
}
for(int i = 1; i <= n; ++i) {
del(a[i]);
for(int x = 1; x < M; ++x) {
if(dp[x] > 0 && 2 * x > sum - a[i]) {
int need = 2 * x - sum + a[i];
cnt[need]++;
}
}
add(a[i]);
}
vector<int> ans;
for(int x = 1; x < M; ++x) if(cnt[x] == n) ans.pb(x);
cout << sz(ans) << nl;
for(auto x : ans) cout << x << ' ';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case #" << i << ": ";
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |