# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1099935 | nnqw | Bootfall (IZhO17_bootfall) | C++17 | 0 ms | 348 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 N = 505;
int a[N];
int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
int totalSum = accumulate(a + 1, a + n + 1, 0);
vector<int> A;
for(int x = 0; x <= totalSum; ++x) {
a[n + 1] = x; // Include Tima's strength
int currentSum = totalSum + x;
// If the total sum is odd, skip to the next x
if (currentSum % 2 != 0) continue;
int half = currentSum / 2;
vector<bool> dp(half + 1, false);
dp[0] = true;
// Fill the DP table
for(int i = 1; i <= n + 1; ++i) {
int strength = a[i];
for(int j = half; j >= strength; --j) {
dp[j] = dp[j] || dp[j - strength];
}
}
// Check if we can achieve the half-sum
if (dp[half]) {
A.push_back(x);
}
}
printf("%d\n", (int)A.size());
for(int i : A)
printf("%d ", i);
puts("");
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... |