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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);
int main() {
int n;
cin >> n;
vector<int> nums;
bitset<250001> ans;
ans.flip();
int sum = 0;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
sum += temp;
nums.push_back(temp);
}
for (int i = 0; i < n; i++) {
bitset<250001> dp;
dp[0] = 1;
for (int j = 0; j < n; j++) {
if (i == j) {
continue;
}
dp |= (dp << nums[j]);
}
int curSum = sum - nums[i];
for (int j = 0; j < 250001; j++) {
if (2*j > curSum) {
ans[j] = 0;
continue;
}
ans[curSum - j - j] = ans[curSum - j - j] & dp[j];
}
}
cout << ans.count() - 1 << endl;
for (int i = 1; i < 250000; i++) {
if (ans[i] == 1) {
cout << i + 1 << endl;
}
}
}
# | 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... |