#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double cur = rngesus(0, MASK(60) - 1);
cur /= MASK(60) - 1;
return l + cur * (r - l);
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const ll MOD = 1000000007LL * 1000000009;
int main(void){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
clock_t start = clock();
int n; cin >> n;
vector<int> a(n);
for(int i= 0; i<n; ++i) cin >> a[i];
int s = 0;
for(int i: a) s += i;
vector<ll> dp(s + 1);
dp[0] = 1;
for(int i: a){
for(int j = s; j >= i; --j){
dp[j] += dp[j - i];
if (dp[j] >= MOD) dp[j] -= MOD;
}
}
if (s % 2 || dp[s / 2] == 0){
cout << 0 << "\n";
return 0;
}
vector<int> valid;
for(int i = 1; i<=s; ++i) valid.push_back(i);
for(int i: a){
for(int j = i; j <= s; ++j){
dp[j] -= dp[j - i];
if (dp[j] < 0) dp[j] += MOD;
}
int _s = s - i;
vector<int> tmp; tmp.reserve(valid.size());
for(int j: valid){
int l = (_s - j), r = (_s + j);
if (l >= 0 && l % 2 == 0 && dp[l / 2]){
tmp.push_back(j);
}
else if (r <= s * 2 && r % 2 == 0 && dp[r / 2]){
tmp.push_back(j);
}
}
valid = tmp;
for(int j = s; j >= i; --j){
dp[j] += dp[j - i];
if (dp[j] >= MOD) dp[j] -= MOD;
}
}
cout << valid.size() << "\n";
printArr(valid);
cerr << "Time elapsed: " << clock() - start << " ms\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
5 ms |
600 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
536 KB |
Output is correct |
29 |
Correct |
3 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
556 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
5 ms |
600 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
536 KB |
Output is correct |
29 |
Correct |
3 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
556 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
4 ms |
348 KB |
Output is correct |
37 |
Correct |
25 ms |
836 KB |
Output is correct |
38 |
Correct |
26 ms |
860 KB |
Output is correct |
39 |
Correct |
37 ms |
1248 KB |
Output is correct |
40 |
Correct |
57 ms |
1032 KB |
Output is correct |
41 |
Correct |
47 ms |
1500 KB |
Output is correct |
42 |
Correct |
50 ms |
952 KB |
Output is correct |
43 |
Correct |
87 ms |
1244 KB |
Output is correct |
44 |
Correct |
88 ms |
1384 KB |
Output is correct |
45 |
Correct |
95 ms |
1264 KB |
Output is correct |
46 |
Correct |
33 ms |
856 KB |
Output is correct |
47 |
Correct |
53 ms |
1052 KB |
Output is correct |
48 |
Correct |
82 ms |
1404 KB |
Output is correct |
49 |
Correct |
60 ms |
1248 KB |
Output is correct |
50 |
Correct |
55 ms |
1108 KB |
Output is correct |
51 |
Correct |
6 ms |
604 KB |
Output is correct |
52 |
Correct |
113 ms |
1504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
5 ms |
600 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
536 KB |
Output is correct |
29 |
Correct |
3 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
556 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
4 ms |
348 KB |
Output is correct |
37 |
Correct |
25 ms |
836 KB |
Output is correct |
38 |
Correct |
26 ms |
860 KB |
Output is correct |
39 |
Correct |
37 ms |
1248 KB |
Output is correct |
40 |
Correct |
57 ms |
1032 KB |
Output is correct |
41 |
Correct |
47 ms |
1500 KB |
Output is correct |
42 |
Correct |
50 ms |
952 KB |
Output is correct |
43 |
Correct |
87 ms |
1244 KB |
Output is correct |
44 |
Correct |
88 ms |
1384 KB |
Output is correct |
45 |
Correct |
95 ms |
1264 KB |
Output is correct |
46 |
Correct |
33 ms |
856 KB |
Output is correct |
47 |
Correct |
53 ms |
1052 KB |
Output is correct |
48 |
Correct |
82 ms |
1404 KB |
Output is correct |
49 |
Correct |
60 ms |
1248 KB |
Output is correct |
50 |
Correct |
55 ms |
1108 KB |
Output is correct |
51 |
Correct |
6 ms |
604 KB |
Output is correct |
52 |
Correct |
113 ms |
1504 KB |
Output is correct |
53 |
Correct |
107 ms |
1144 KB |
Output is correct |
54 |
Correct |
125 ms |
1388 KB |
Output is correct |
55 |
Correct |
243 ms |
2056 KB |
Output is correct |
56 |
Correct |
111 ms |
1380 KB |
Output is correct |
57 |
Correct |
253 ms |
2296 KB |
Output is correct |
58 |
Correct |
146 ms |
1320 KB |
Output is correct |
59 |
Correct |
171 ms |
1504 KB |
Output is correct |
60 |
Correct |
15 ms |
856 KB |
Output is correct |
61 |
Correct |
192 ms |
1760 KB |
Output is correct |
62 |
Correct |
202 ms |
1924 KB |
Output is correct |
63 |
Correct |
241 ms |
2060 KB |
Output is correct |
64 |
Correct |
206 ms |
2100 KB |
Output is correct |
65 |
Correct |
39 ms |
1112 KB |
Output is correct |
66 |
Correct |
52 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
5 ms |
600 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
536 KB |
Output is correct |
29 |
Correct |
3 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
556 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
4 ms |
348 KB |
Output is correct |
37 |
Correct |
25 ms |
836 KB |
Output is correct |
38 |
Correct |
26 ms |
860 KB |
Output is correct |
39 |
Correct |
37 ms |
1248 KB |
Output is correct |
40 |
Correct |
57 ms |
1032 KB |
Output is correct |
41 |
Correct |
47 ms |
1500 KB |
Output is correct |
42 |
Correct |
50 ms |
952 KB |
Output is correct |
43 |
Correct |
87 ms |
1244 KB |
Output is correct |
44 |
Correct |
88 ms |
1384 KB |
Output is correct |
45 |
Correct |
95 ms |
1264 KB |
Output is correct |
46 |
Correct |
33 ms |
856 KB |
Output is correct |
47 |
Correct |
53 ms |
1052 KB |
Output is correct |
48 |
Correct |
82 ms |
1404 KB |
Output is correct |
49 |
Correct |
60 ms |
1248 KB |
Output is correct |
50 |
Correct |
55 ms |
1108 KB |
Output is correct |
51 |
Correct |
6 ms |
604 KB |
Output is correct |
52 |
Correct |
113 ms |
1504 KB |
Output is correct |
53 |
Correct |
107 ms |
1144 KB |
Output is correct |
54 |
Correct |
125 ms |
1388 KB |
Output is correct |
55 |
Correct |
243 ms |
2056 KB |
Output is correct |
56 |
Correct |
111 ms |
1380 KB |
Output is correct |
57 |
Correct |
253 ms |
2296 KB |
Output is correct |
58 |
Correct |
146 ms |
1320 KB |
Output is correct |
59 |
Correct |
171 ms |
1504 KB |
Output is correct |
60 |
Correct |
15 ms |
856 KB |
Output is correct |
61 |
Correct |
192 ms |
1760 KB |
Output is correct |
62 |
Correct |
202 ms |
1924 KB |
Output is correct |
63 |
Correct |
241 ms |
2060 KB |
Output is correct |
64 |
Correct |
206 ms |
2100 KB |
Output is correct |
65 |
Correct |
39 ms |
1112 KB |
Output is correct |
66 |
Correct |
52 ms |
1244 KB |
Output is correct |
67 |
Correct |
210 ms |
1756 KB |
Output is correct |
68 |
Correct |
43 ms |
1372 KB |
Output is correct |
69 |
Correct |
683 ms |
3896 KB |
Output is correct |
70 |
Correct |
426 ms |
2616 KB |
Output is correct |
71 |
Correct |
407 ms |
2420 KB |
Output is correct |
72 |
Correct |
381 ms |
2252 KB |
Output is correct |
73 |
Correct |
351 ms |
2256 KB |
Output is correct |
74 |
Correct |
746 ms |
4192 KB |
Output is correct |
75 |
Correct |
567 ms |
3188 KB |
Output is correct |
76 |
Correct |
757 ms |
4280 KB |
Output is correct |
77 |
Correct |
748 ms |
4196 KB |
Output is correct |