# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
530740 | Killer2501 | Bootfall (IZhO17_bootfall) | C++14 | 295 ms | 3856 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 ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 5e2+5;
const int M = 250;
const int mod = 1e9+7;
const ll base = 75;
const int inf = 1e9;
int n, t, b[N*N], d[N], lab[N], c[N], a[N];
int ans, tong;
ll dp[N*N];
ll m, k;
pii p[N], start, finish;
vector<int> gx[N], gy[N];
vector<pii> vi;
string s[N];
void sol()
{
cin >> n;
dp[0] = 1;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
for(int j = tong; j >= 0; j --)dp[j+a[i]] += dp[j];
tong += a[i];
}
if((tong&1) || dp[tong>>1]==0)
{
cout << 0;
return;
}
for(int i = 1; i <= n; i ++)
{
for(int j = a[i]; j <= tong; j ++)dp[j] -= dp[j-a[i]];
tong -= a[i];
for(int j = (tong&1); j <= tong; j += 2)
if(dp[(tong+j)>>1])++b[j];
for(int j = tong; j >= 0; j --)dp[j+a[i]] += dp[j];
tong += a[i];
}
for(int i = 0; i < N*N; i ++)if(b[i] == n)++ans;
cout << ans << '\n';
for(int i = 0; i < N*N; i ++)if(b[i] == n)cout << i <<" ";
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
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... |