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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
ofstream fout(".out");
ifstream fin(".in");
int n;
ll arr[501], dp[250001];
ll sum;
bool ans[250001];
void remove(ll x) {
for(int i = x; i <= sum; i++)
dp[i] = (dp[i] - dp[i - x] + mod) % mod;
}
void add(ll x) {
for(int i = sum; i >= x; i--)
dp[i] = (dp[i] + dp[i - x]) % mod;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
dp[0] = 1;
for(int i = 0; i < n; i++) {
for(int j = sum; j >= arr[i]; j--)
dp[j] = (dp[j] + dp[j - arr[i]]) % mod;
}
if(sum % 2 || !dp[sum / 2]) {
cout << 0;
return 0;
}
for(int i = 1; i <= sum; i++)
ans[i] = 1;
int anss = sum;
for(int i = 0; i < n; i++) {
remove(arr[i]);
for(int j = 1; j <= sum; j++) {
if(!ans[j])
continue;
ll x = sum - arr[i] + j;
add(j);
if(j % 2 != arr[i] % 2 || !dp[x / 2]) {
ans[j] = 0;
anss--;
}
remove(j);
}
add(arr[i]);
}
cout << anss << "\n";
for(int i = 1; i <= sum; i++) {
if(ans[i])
cout << i << " ";
}
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... |