This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 500;
const ll M = N * N;
const ll mod = 1e9 + 7;
const ll inf = 3e18;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T> void vout(T s){cout << s << endl;exit(0);}
int dp[MAXN], kol[MAXN];
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0);
dp[0] = 1;
int n;
cin >> n;
vector <int> a(n + 1);
for(int i = 1; i <= n; i++)cin >> a[i];
int sc = 0;
vector <int> pref(n + 1);
for(int i = 1; i <= n; i++){
for(int j = pref[i - 1] + a[i]; j >= a[i]; j--)(dp[j] += dp[j - a[i]]) %= mod;
pref[i] = pref[i - 1] + a[i];
}
sc = pref[n];
if(sc % 2)vout(0);
if(!dp[sc / 2])vout(0);
int S;
for(int i = 1; i <= n; i++){
for(int j = a[i]; j <= pref[n]; j++){
dp[j] -= dp[j - a[i]];
if(dp[j] < 0)dp[j] += mod;
}
for(int j = 1; j <= pref[n]; j++){
S = sc - a[i] + j;
if(S % 2 == 0 && dp[S / 2])kol[j]++;
}
for(int j = pref[n]; j >= a[i]; j--){
(dp[j] += dp[j - a[i]]) %= mod;
}
}
vector <int> ans;
for(int i = 1; i < MAXN; i++)if(kol[i] == n)ans.p_b(i);
cout << ans.size() << "\n";
for(auto i : ans)cout << i << " ";
cout << "\n";
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... |