# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
534762 | fadi57 | Bootfall (IZhO17_bootfall) | C++14 | 473 ms | 5764 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 mx=3e5+900;
const int mx2=1e6+9;
typedef long long ll;
const int mod=998244353 ;
const int SQ=400;
const ll inf=1e9+10;
ll dp[mx],sum,freq[mx],a[mx];
int main(){
int t;t=1;
while(t--){
int n;
cin>>n;
dp[0]=1;
int last=0;
for(int i=1;i<=n;i++){
cin>>a[i];
sum+=a[i];
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++){
for(int j=mx-5;j>=a[i];j--){
dp[j]+=dp[j-a[i]];
}
}
if(sum%2!=0||dp[sum/2]==0){
cout<<0;
return 0;
}
for(int i=1;i<=n;i++){
for(int j=a[i];j<=mx-5;j++){
dp[j]-=dp[j-a[i]];
}
sum-=a[i];
for(int summ=0;summ<=mx-5;summ++){
if(dp[summ]){
int rest=sum-summ;
if(rest-summ<0){continue;}
freq[rest-summ]++;
}
}
for(int j=mx-5;j>=a[i];j--){
dp[j]+=dp[j-a[i]];
}
sum+=a[i];
}
vector<int >ans;
for(int i = 0; i <= mx-5; i++){
if(freq[i] == n){
ans.push_back(i);
}
}
cout << ans.size() << endl;
for(auto it : ans)
cout << it << " ";
}
}
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... |