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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 2e6+12,INF = 1e18+7;
int q[N],dp[N],sum;
void add(int x){
for (int i = sum;i>=0;--i)
dp[i+x] += dp[i];
}
void del(int x){
for (int i = 0;i <= sum;++i)
dp[i+x] -= dp[i];
}
int cnt[N];
main(){
int n,i,j;
cin>>n;
dp[0]=1;
for (i=1;i<=n;++i){
cin>>q[i];
add(q[i]);
sum += q[i];
}
if (sum&1 || dp[sum/2] == 0){
cout <<0;
ret 0;
}
for (i=1;i<=n;++i){
del(q[i]);
sum -= q[i];
for (j = sum/2; j <= sum;++j){
if (dp[j] && j*2 > sum){
cnt[j*2-sum]++;
}
}
sum += q[i];
add(q[i]);
}
vector <int> ans;
for (i=1;i<=sum;++i)
if (cnt[i] == n)
ans.pb(i);
cout <<ans.size()<<"\n";
for (auto x:ans)cout <<x<<" ";
}
Compilation message (stderr)
bootfall.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main(){
| ^~~~
# | 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... |