# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93832 | dalgerok | Bootfall (IZhO17_bootfall) | C++14 | 149 ms | 2292 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 int long long
using namespace std;
const int N = 505, M = 1e7 + 5, MOD = 1e9 + 9;
int n, a[N], sum, ssum;
bool used[M];
long long dp[M];
inline void Add(int val){
sum += val;
for(int i = sum; i >= 0; i--){
dp[i + val] += dp[i];
if(dp[i + val] >= MOD){
dp[i + val] -= MOD;
}
}
}
inline void Del(int val){
for(int i = 0; i <= sum; i++){
dp[i + val] -= dp[i];
if(dp[i + val] < 0){
dp[i + val] += MOD;
}
}
sum -= val;
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
dp[0] = 1;
for(int i = 1; i <= n; i++){
cin >> a[i];
ssum += a[i];
Add(a[i]);
}
for(int i = 1; i <= ssum; i++){
used[i] = true;
}
if(ssum % 2 || dp[ssum / 2] == 0){
return cout << 0, 0;
}
for(int i = 1; i <= n; i++){
Del(a[i]);
for(int j = 1; j <= ssum; j++){
if((sum + j) % 2 || dp[(sum + j) / 2] == 0){
used[j] = false;
}
}
Add(a[i]);
}
vector < int > ans;
for(int i = 1; i <= ssum; i++){
if(used[i]){
ans.push_back(i);
}
}
cout << (int)ans.size() << "\n";
for(auto it : ans){
cout << it << " ";
}
}
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... |