# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673573 | smartmonky | Bootfall (IZhO17_bootfall) | C++14 | 363 ms | 3520 KiB |
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>
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
const int N = 501 * 500;
int dp[N];
int used[N];
int main()
{
int n, sum = 0;
cin >> n;
vector <int> v(n);
for(int i = 0; i < n; i++){
cin >> v[i];
sum += v[i];
}
if(sum & 1){
cout << 0;
return 0;
}
dp[0] = 1;
for(int i = 0; i < n; i++){
for(int j = sum; j >= v[i]; j--){
dp[j] += dp[j - v[i]];
}
}
if(!dp[sum / 2]){
cout << 0;
return 0;
}
vector <int> ans;
for(int i = 0; i < n; i++){
int k = sum - v[i];
for(int j = v[i]; j <= sum; j++){
dp[j] -= dp[j - v[i]];
}
for (int j = 0; j <= k / 2; j++) {
if (dp[j]) used[k - j * 2]++;
}
for(int j = sum ; j >= v[i]; j--){
dp[j] += dp[j - v[i]];
}
}
for (int i = 0; i <= sum; i++) {
if (used[i] == n)
ans.pb(i);
}
cout << ans.size() << endl;
for(auto x : ans)
cout << x <<" ";
}
Compilation message (stderr)
# | 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... |