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>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const int MAXN = 510;
const int MOD = 1e9 + 7;
int f[MAXN * MAXN];
int dp[MAXN * MAXN];
int a[MAXN];
int s = 0;
void add(int x){
s += x;
for(int i = MAXN * MAXN - 1; i >= x; i--){
dp[i] = dp[i] + dp[i - x];
dp[i] %= MOD;
}
}
void del(int x){
s -= x;
for(int i = x; i < MAXN * MAXN; i++){
dp[i] = dp[i] - dp[i - x] + MOD;
dp[i] %= MOD;
}
}
void solve(){
int n;
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
}
dp[0] = 1;
for(int i = 0; i < n; i++){
add(a[i]);
}
if(s % 2 == 1){
cout << "0\n";
return;
}
if(dp[s / 2] == 0){
cout << "0\n";
return;
}
for(int i = 0; i < n; i++){
del(a[i]);
for(int j = 0; j <= s / 2; j++){
if(dp[j]){
f[s - 2 * j]++;
}
}
add(a[i]);
}
vi res;
for(int i = 0; i < MAXN * MAXN; i++){
if(f[i] == n){
res.pb(i);
}
}
cout << sz(res) << '\n';
for(auto ele : res){
cout << ele << ' ';
}
cout << '\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
//cin >> t;
while(t--){
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... |