#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define lft(x) x * 2
#define rgt(x) x * 2 + 1
#define tm hui_pizda
#define ft first
#define sd second
#define pb push_back
#define pf push_front
#define sz size()
#define cnt continue
#define m_p make_pair
#define fr(i, l, r) for(int i = l; i <= r; ++ i)
#define rf(i, r, l) for(int i = r; i >= l; -- i)
#define all(x) x.begin(), x.end()
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using _set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef int ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <pii> vpi;
typedef vector <pll> vpl;
mt19937_64 rnd(time(NULL));
const ll N = 1e6 + 10;
const ll mtrxN = 10;
//const ll oo = 1e18 + 10;
const ll oo = 1e9 + 10;
const ll B = 500;
const ll mod = 1e9 + 7;
struct mtrx{
ll m[mtrxN][mtrxN] = {};
};
mtrx mtrx_mult(mtrx a, mtrx b){
mtrx c;
fr(i, 0, mtrxN - 1){
fr(j, 0, mtrxN - 1){
ll sum = 0;
fr(x, 0, mtrxN - 1){
sum += a.m[i][x] * b.m[x][j];
sum %= mod;
}
c.m[i][j] = sum;
}
}
return c;
}
mtrx mtrx_pow(mtrx a, ll n){
mtrx res;
fr(i, 0, mtrxN - 1)fr(j, 0, mtrxN - 1)res.m[i][j] = a.m[i][j];
n --;
while(n){
if(n&1)res = mtrx_mult(res, a);
a = mtrx_mult(a, a);
n >>= 1;
}
return res;
}
ll _pow(ll a, ll n){
ll r = 1;
while(n){
if(n&1)r = r * a % mod;
a = a * a % mod;
n >>= 1;
}
return r;
}
ll div(ll x, ll y, ll md){
return x * _pow(y, md - 2) % md;
}
ll a[N];
ll n, NN;
vector <bool> calc(ll x){
vector <ll> dp;
dp.resize(NN + 1);
dp[0] = 1;
fr(i, 1, n)
if(i != x)rf(j, NN, a[i])dp[j] |= dp[j - a[i]];
vector <bool> rz(NN + 1);
fr(i, 0, NN)if(dp[i])rz[abs(i - (NN - a[x] - i))] = 1;
return rz;
}
int main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//NN = 10;
NN = 0;
cin >> n;
if(n % 2 == 1)return cout << 0, 0;
fr(i, 1, n)cin >> a[i], NN += a[i];
vector <bool> ans(NN + 1, 1);
fr(i, 0, n){
vector <bool> now = calc(i);
if(i == 0){
if(!now[NN])return cout << 0, 0;
else cnt;
}
bool ok = 0;
fr(j, 0, NN){
ans[j] = ans[j] & now[j];
ok |= ans[j];
}
if(!ok)return cout << 0, 0;
}
set <ll> ra;
fr(i, 0, NN)
if(ans[i])ra.insert(i);
cout << ra.sz << endl;
for(auto i : ra)cout << i << ' ';
cout << endl;
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
380 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
420 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
380 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
420 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
12 ms |
504 KB |
Output is correct |
22 |
Correct |
16 ms |
376 KB |
Output is correct |
23 |
Correct |
7 ms |
376 KB |
Output is correct |
24 |
Correct |
31 ms |
504 KB |
Output is correct |
25 |
Correct |
58 ms |
504 KB |
Output is correct |
26 |
Correct |
69 ms |
504 KB |
Output is correct |
27 |
Correct |
62 ms |
504 KB |
Output is correct |
28 |
Correct |
67 ms |
440 KB |
Output is correct |
29 |
Correct |
68 ms |
376 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
31 |
Correct |
56 ms |
504 KB |
Output is correct |
32 |
Correct |
37 ms |
504 KB |
Output is correct |
33 |
Correct |
69 ms |
440 KB |
Output is correct |
34 |
Correct |
67 ms |
436 KB |
Output is correct |
35 |
Correct |
67 ms |
376 KB |
Output is correct |
36 |
Correct |
35 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
380 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
420 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
12 ms |
504 KB |
Output is correct |
22 |
Correct |
16 ms |
376 KB |
Output is correct |
23 |
Correct |
7 ms |
376 KB |
Output is correct |
24 |
Correct |
31 ms |
504 KB |
Output is correct |
25 |
Correct |
58 ms |
504 KB |
Output is correct |
26 |
Correct |
69 ms |
504 KB |
Output is correct |
27 |
Correct |
62 ms |
504 KB |
Output is correct |
28 |
Correct |
67 ms |
440 KB |
Output is correct |
29 |
Correct |
68 ms |
376 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
31 |
Correct |
56 ms |
504 KB |
Output is correct |
32 |
Correct |
37 ms |
504 KB |
Output is correct |
33 |
Correct |
69 ms |
440 KB |
Output is correct |
34 |
Correct |
67 ms |
436 KB |
Output is correct |
35 |
Correct |
67 ms |
376 KB |
Output is correct |
36 |
Correct |
35 ms |
504 KB |
Output is correct |
37 |
Correct |
517 ms |
892 KB |
Output is correct |
38 |
Correct |
533 ms |
872 KB |
Output is correct |
39 |
Execution timed out |
1062 ms |
760 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
380 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
420 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
12 ms |
504 KB |
Output is correct |
22 |
Correct |
16 ms |
376 KB |
Output is correct |
23 |
Correct |
7 ms |
376 KB |
Output is correct |
24 |
Correct |
31 ms |
504 KB |
Output is correct |
25 |
Correct |
58 ms |
504 KB |
Output is correct |
26 |
Correct |
69 ms |
504 KB |
Output is correct |
27 |
Correct |
62 ms |
504 KB |
Output is correct |
28 |
Correct |
67 ms |
440 KB |
Output is correct |
29 |
Correct |
68 ms |
376 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
31 |
Correct |
56 ms |
504 KB |
Output is correct |
32 |
Correct |
37 ms |
504 KB |
Output is correct |
33 |
Correct |
69 ms |
440 KB |
Output is correct |
34 |
Correct |
67 ms |
436 KB |
Output is correct |
35 |
Correct |
67 ms |
376 KB |
Output is correct |
36 |
Correct |
35 ms |
504 KB |
Output is correct |
37 |
Correct |
517 ms |
892 KB |
Output is correct |
38 |
Correct |
533 ms |
872 KB |
Output is correct |
39 |
Execution timed out |
1062 ms |
760 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
380 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
420 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
12 ms |
504 KB |
Output is correct |
22 |
Correct |
16 ms |
376 KB |
Output is correct |
23 |
Correct |
7 ms |
376 KB |
Output is correct |
24 |
Correct |
31 ms |
504 KB |
Output is correct |
25 |
Correct |
58 ms |
504 KB |
Output is correct |
26 |
Correct |
69 ms |
504 KB |
Output is correct |
27 |
Correct |
62 ms |
504 KB |
Output is correct |
28 |
Correct |
67 ms |
440 KB |
Output is correct |
29 |
Correct |
68 ms |
376 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
31 |
Correct |
56 ms |
504 KB |
Output is correct |
32 |
Correct |
37 ms |
504 KB |
Output is correct |
33 |
Correct |
69 ms |
440 KB |
Output is correct |
34 |
Correct |
67 ms |
436 KB |
Output is correct |
35 |
Correct |
67 ms |
376 KB |
Output is correct |
36 |
Correct |
35 ms |
504 KB |
Output is correct |
37 |
Correct |
517 ms |
892 KB |
Output is correct |
38 |
Correct |
533 ms |
872 KB |
Output is correct |
39 |
Execution timed out |
1062 ms |
760 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |