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 f first
#define s second
#define pb push_back
#define pii pair <int,ll>
#define left (h<<1),l,((l + r)>>1)
#define right ((h<<1)|1),((l + r)>>1) + 1,r
using namespace std;
int sum,a[505];
vector <int> ans;
bitset <10005> dp;
bool DP[250005];
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i = 1; i <= n; i++)
cin>>a[i],sum += a[i];
DP[0] = 1;
for (int i = 1; i <= n; i++){
for (int j = sum - a[i]; j >= 0; j--)
DP[j + a[i]] |= DP[j];
}
if (sum & 1 || !DP[sum/2]){
cout<<0;
exit(0);
}
++n;
for (int x = 1; x <= sum; x++){
//x-s vamatebt axla
a[n] = x;
int can = 1;
for (int j = 1; j <= n; j++){
//j amovagdot
int target = (sum + x - a[j]);
if (target&1){
can=0;
break;
}
target/=2;
dp = 0;
dp[0] = 1;
for (int i = 1; i <= n; i++){
if (i != j) dp |= (dp << a[i]);
if (dp[target]) break;
}
if (!dp[target]) {
can = 0;
break;
}
}
if (can){
ans.pb(x);
}
}
cout<<ans.size()<<endl;
for (int x: ans)
cout<<x<<" ";
}
# | 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... |