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 ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 355;
int v[N];
bool is[N*N];
set<int> x[N];
int main(){
// freopen("file.txt", "r", stdin);
int n, sm = 0, copy;
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", v+i), sm += v[i];
vector<bool> odp(sm+1, false);
odp[0] = 1;
for(int i = 1; i <= n; ++i)
for(int j = sm; j >= v[i]; --j)
if(odp[j-v[i]])
odp[j] = 1;
if(sm&1 or !odp[sm/2]){
puts("0");
return 0;
}
for(int i = 0; i <= sm; ++i)
is[i] = 1;
copy = sm;
// 3
// 2 2 2
for(int ad = 1; ad <= n; ++ad){
sm -= v[ad];
vector<bool> dp(sm+1, false);
dp[0] = 1;
for(int i = 1; i <= n; ++i)
if(i!=ad)
for(int j = sm; j >= v[i]; --j)
if(dp[j-v[i]])
dp[j] = 1;
// for(int i = 0; i <= sm; ++i)
// if(dp[i])
// printf("%d ", i);
// puts("");
// wr;
for(int i = 0; i <= sm; ++i)
if(dp[i])
x[ad].insert(abs(sm-2*i));
sm = copy;
}
// for(int i = 1; i <= n; ++i){
// for(auto to : x[i])
// printf("%d ", to);
// if(!x[i].empty())
// puts("");
// }
// wr;
// return 0;
for(int ad = 1; ad <= n; ++ad)
for(int i = 0; i <= sm; ++i){
if(!is[i])
continue;
if(!x[ad].count(i))
is[i] = 0;
}
vector<int> ans;
for(int i = 0; i <= sm; ++i)
if(is[i])
ans.pb(i);
printf("%d\n", (int)ans.size());
for(auto i : ans)
printf("%d ", i);
puts("");
return 0;
}
Compilation message (stderr)
bootfall.cpp: In function 'int main()':
bootfall.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
bootfall.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d", v+i), sm += v[i];
| ~~~~~^~~~~~~~~~~
# | 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... |