# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38792 | DenXman111 | Bootfall (IZhO17_bootfall) | C++14 | 423 ms | 7920 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>
const int MAXN = 323456;
using namespace std;
int a[MAXN], ans[MAXN], dp[MAXN], d[MAXN];
int main()
{
// freopen("bootfall.in", "r", stdin);
// freopen("bootfall.out", "w", stdout);
int n, i, j, sum = 0, x = 0;
cin >> n;
dp[0] = 1;
for (i = 1; i <= n; i++){
cin >> a[i];
for (j = sum; j >= 0; j--) dp[j + a[i]] += dp[j];
sum += a[i];
}
if (sum % 2 == 1 || dp[sum / 2] == 0) return cout << 0 << endl, 0;
for (j = 0; j <= sum; j++) d[j] = dp[j];
for (i = 1; i <= n; i++){
for (j = 0; j <= sum; j++) {
d[j + a[i]] -= d[j];
x = abs(sum - j - a[i] - j);
if (d[j] != 0 && ans[x] == i - 1) ans[x] = i;
d[j] = dp[j];
}
}
vector < int > v;
for (i = 0; i <= sum; i++) if (ans[i] == n) v.push_back(i);
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... |