# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672187 | ReLice | Bootfall (IZhO17_bootfall) | C++14 | 235 ms | 5752 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"
#define ll long long
#define ld long double
#define int long long
#define pb push_back
#define sz size()
#define fr first
#define sc second
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll N=1e5+1;
const ll inf=1e9+7;
ll dp[250001],used[250001];
main(){
start();
ll n,k,i,j,b,mx=-1;
cin >> n;
vector <ll> ans;
ll sum=0,a[n];
for (i=0;i<n;i++) {
cin>>a[i];
sum+=a[i];
}
dp[0]++;
for(i=0;i<n;i++)
for(j=sum;j-a[i]>=0;j--)
dp[j]+=dp[j-a[i]];
if(!dp[sum/2] || sum%2) {
cout<<0;
exit(0);
}
for (i=0;i<n;i++) {
ll cur=sum-a[i];
for(j=a[i];j<=sum;j++) {
dp[j]-=dp[j-a[i]];
}
for(ll j=0;j<=cur/2;j++){
if(dp[j])used[cur-j*2]++;
}
for(ll j=sum;j>=a[i];j--){
dp[j]+=dp[j-a[i]];
}
}
for(ll i=0;i<=sum;i++) {
if(used[i]==n) ans.pb(i);
}
cout<<ans.sz<<'\n';
for (auto i : ans) cout<<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... |