# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
598438 | SuffixAutomata | Bootfall (IZhO17_bootfall) | C++17 | 556 ms | 3708 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 MOD = 1000000007;
int dp[500 * 500 + 1], dp2[500 * 500 + 1];
bool ok[500 * 500 + 1];
int main() {
int n;
cin >> n;
vector<int> ar(n);
int sm = 0;
dp[0] = 1;
for (int i = 0; i < n; i++) {
cin >> ar[i];
for (int j = sm; j >= 0; j--)
dp[j + ar[i]] = (dp[j + ar[i]] + dp[j]) % MOD;
sm += ar[i];
}
auto x = [&](int i) {
if (i < 0 || i % 2 || i / 2 > sm)
return 0;
return dp2[i / 2];
};
vector<int> ans;
if (sm % 2 == 0 && dp[sm / 2]) {
for (int v = 0; v <= 500 * 500; v++)
ok[v] = 1;
for (int i : ar) {
memcpy(dp2, dp, sizeof dp2);
for (int j = 0; j <= sm - i; j++)
dp2[j + i] = (dp2[j + i] + MOD - dp2[j]) % MOD;
for (int v = 0; v <= 500 * 500; v++)
ok[v] = ok[v] && ((x(sm + v - i) + x(sm - v - i)) % MOD);
}
for (int v = 0; v <= 500 * 500; v++)
if (ok[v])
ans.push_back(v);
}
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << " \n"[i == ans.size() - 1];
}
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... |