# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566503 | 1zaid1 | Bootfall (IZhO17_bootfall) | C++14 | 1083 ms | 324 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;
#define endl '\n'
typedef long long ll;
#define int long long
#pragma GCC diagnostic ignored "-Wunused-result"
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
cout << fixed << setprecision(15);
if (name.size()) {
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
const int M = 5e2+5, MOD = 1e6+7;
int sum;
bool check(vector<int>& v) {
if (sum%2) return 0;
vector<bool> can(2*sum+10, 0); can[0] = 1;
for (int i = 0; i < v.size(); i++) {
for (int k = sum/2; k >= v[i]; k--) {
if (can[k-v[i]]) can[k] = 1;
}
} return can[sum/2];
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
srand(time(0));
// setIO("citystate");
int n;
cin >> n;
vector<int> v(n);
for (int&i:v) cin >> i;
for (int i:v) sum += i;
if (!check(v)) {
cout << 0 << endl;
return 0;
}
vector<int> ans;
for (int i = 1; i <= sum; i++) {
bool ok = 1;
for (int j = 0; j < n; j++) {
sum += i-v[j];
swap(v[j], i);
ok &= check(v);
swap(v[j], i);
sum -= i-v[j];
}
if (ok) ans.push_back(i);
}
cout << ans.size() << endl;
for (int i:ans) cout << i << ' '; cout << endl;
return 0;
}
/*
4
1 3 1 5
*/
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... |