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];
bool f[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]];
if(dp[j] >= mod)dp[j] -= mod;
}
pref[i] = pref[i - 1] + a[i];
}
sc = pref[n];
if(sc % 2)vout(0);
if(!dp[sc / 2])vout(0);
int S;
vector <int> ans, can;
for(int i = 1; i <= pref[n]; i++)ans.p_b(i);
for(int i = 1; i <= n; i++){
if(f[a[i]])continue;
f[a[i]] = 1;
for(int j = a[i]; j <= pref[n]; j++){
dp[j] -= dp[j - a[i]];
if(dp[j] < 0)dp[j] += mod;
}
for(auto j : ans){
S = sc - a[i] + j;
if(S % 2 == 0 && dp[S / 2])can.p_b(j);
}
ans.clear();
ans = can;
can.clear();
for(int j = pref[n]; j >= a[i]; j--){
dp[j] += dp[j - a[i]];
if(dp[j] >= mod)dp[j] -= mod;
}
}
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... |