This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e5+23, lg = 18;
int Mod = 1e9+7; //998244353;
inline int MOD(int a, int mod=Mod) {
while(a>=mod) {a-=mod;}
(a<0)&&(a+=mod);
return a;
}
int n, sum, a[505], res[505*505], dp[505*505];
void add(int i) {
for(int x=500*500; x>=a[i]; x--) {
dp[x] = (dp[x] + dp[x-a[i]]);
if(dp[x]>=Mod) dp[x]-=Mod;
}
}
void del(int i) {
for(int x=a[i]; x<=500*500; x++) {
dp[x] = (dp[x] - dp[x-a[i]]);
if(dp[x]<0) dp[x]+=Mod;
}
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) {
cin>>a[i]; sum+=a[i];
}
dp[0] = 1;
for(int i=1; i<=n; i++) {
add(i);
}
if(dp[sum/2] == 0 || sum%2==1) kill(0);
for(int i=1; i<=n; i++) {
del(i);
int x = (sum-a[i])%2;
for(int j=(x==0?2:1); j<=500*500; j+=2) {
res[j] |= (dp[(sum-a[i]+j)/2] == 0);
}
for(int j=(x==0?1:2); j<=500*500; j+=2) {
res[j] |= 1;
}
add(i);
}
vector<int> ans;
for(int i=1; i<=500*500; i++) {
if(res[i] == 0) ans.pb(i);
}
cout<<size(ans)<<endl;
for(auto it : ans) {
cout<<it<<' ';
}
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... |