# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38274 | mirbek01 | Bootfall (IZhO17_bootfall) | C++14 | 546 ms | 5796 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>
# define pb push_back
# define fr first
# define sc second
# define mk make_pair
using namespace std;
const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 250005;
typedef long long ll;
int n, a[N], dp[N], cnt[N], s;
vector <int> ans;
int main(){
dp[0] = 1;
scanf("%d", &n);
for(int i = 1; i <= n; i ++){
scanf("%d", &a[i]);
s += a[i];
}
for(int i = 1; i <= n; i ++)
for(int j = s; j - a[i] >= 0; j --)
dp[j] += dp[j - a[i]];
if(s % 2 || !dp[s / 2])
{
cout << 0 << endl;
return 0;
}
for(int i = 1; i <= n; i ++){
int ss = s - a[i];
for(int j = 0; j <= ss; j ++)
dp[j + a[i]] = (dp[j + a[i]] - dp[j]);
for(int j = ss / 2 + 1; j <= ss; j ++)
if(dp[j]) cnt[j * 2 - ss] ++;
for(int j = ss; j >= 0; j --)
dp[j + a[i]] += dp[j];
}
for(int i = 1; i <= s; i ++)
if(cnt[i] == n) ans.pb(i);
printf("%d\n", ans.size());
for(int i : ans)
printf("%d ", 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... |