# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
681996 | boykut | Bootfall (IZhO17_bootfall) | C++14 | 1086 ms | 344 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>
using namespace std;
const int MAX = 600;
int dp[MAX*MAX], can[MAX*MAX];
int a[MAX];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
dp[0] = 1;
for (int i = 0; i < n; i++) {
for (int x = sum; x >= 0; x--) {
dp[x+a[i]] += dp[x];
}
}
if (sum%2 == 1 || dp[sum/2] == 0) {
return cout << 0, 0;
}
fill(can, can+sum+1, 1);
vector<int> ans;
for (int Tima = 1; Tima <= sum; Tima++) {
for (int Without = 0; Without < n; Without++) {
for (int x = 0; x <= sum; x++) {
dp[x+a[Without]] -= dp[x];
}
for (int x = sum; x >= 0; x--) {
dp[x+Tima] += dp[x];
}
if ((sum+a[Without]+Tima)%2 == 1 || dp[(sum-a[Without]+Tima)/2] == 0) {
can[Tima] = 0;
}
for (int x = 0; x <= sum; x++) {
dp[x+Tima] -= dp[x];
}
for (int x = sum; x >= 0; x--) {
dp[x+a[Without]] += dp[x];
}
}
}
for (int Tima = 1; Tima <= sum; Tima++) {
if (can[Tima] == 1)
ans.push_back(Tima);
}
cout << ans.size() << "\n";
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << " ";
}
return 0;
}
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... |