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");
vector<bitset<250001>> dp(501);
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int arr[n];
int sum = 0;
for(int i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
dp[n][0] = 1;
for(int i = 0; i < n; i++) {
dp[n] |= (dp[n] << arr[i]);
dp[n] |= (1 << (arr[i] * 2));
}
if(sum % 2 || !dp[n][sum / 2]) {
cout << 0;
return 0;
}
for(int k = 0; k < n; k++) {
dp[k][0] = 1;
for(int i = 0; i < n; i++) {
if(i == k)
continue;
dp[k] |= (dp[k] << (arr[i] * 2));
}
}
vector<int> ans;
for(int i = 1; i <= sum; i++) {
bool bb = 1;
for(int j = 0; j < n; j++) {
int x = sum - arr[j] + i;
if(i % 2 != arr[j] % 2 || x < 0 || !dp[j][x]) {
bb = 0;
break;
}
}
if(bb)
ans.push_back(i);
}
cout << ans.size() << "\n";
for(int i : ans)
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... |