//君の手を握ってしまったら
//孤独を知らないこの街には
//もう二度と帰ってくることはできないのでしょう
//君が手を差し伸べた 光で影が生まれる
//歌って聞かせて この話の続き
//連れて行って見たことない星まで
//さユリ - 花の塔
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
#define starburst ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define maxn 200005
#define mod 1000000007
void solve(){
int n, sum = 0; cin >> n;
vector<int> v(n);
for(auto &x:v) cin >> x, sum += x;
sort(v.begin(), v.end());
bitset<250005> dp;
dp[0] = 1;
for(int i = 0; i < n; ++i)
dp |= (dp << v[i]);
if(sum % 2 == 1 || dp[sum / 2] == 0){
cout << "0\n";
return;
}
vector<int> cnt(sum + 1, 0);
for(int k = 0; k < n; k += 25){
int nxt = min(k + 25, n);
bitset<250005> cur;
cur[0] = 1;
for(int i = 0; i < k; ++i){
cur |= (cur << v[i]);
}
for(int i = nxt; i < n; ++i){
cur |= (cur << v[i]);
}
for(int j = k; j < nxt; ++j){
bitset<250005> b = cur;
for(int i = k; i < nxt; ++i){
if(j == i) continue;
b |= (b << v[i]);
}
for(int val = sum - v[j]; val >= 0; --val){
if(b[val]) {
int t = val - (sum - val - v[j]);
if(t <= 0) break;
cnt[t]++;
}
}
}
}
set<int> st;
for(int i = 0; i <= sum; ++i){
if(cnt[i] == n) st.insert(i);
}
cout << st.size() << '\n';
for(auto x:st) cout << x << ' ';
}
signed main(){
starburst
int t = 1; //cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
340 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
9 ms |
464 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
464 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
340 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
9 ms |
464 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
464 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
13 ms |
556 KB |
Output is correct |
22 |
Correct |
17 ms |
476 KB |
Output is correct |
23 |
Correct |
10 ms |
468 KB |
Output is correct |
24 |
Correct |
29 ms |
480 KB |
Output is correct |
25 |
Correct |
22 ms |
632 KB |
Output is correct |
26 |
Correct |
24 ms |
624 KB |
Output is correct |
27 |
Correct |
24 ms |
504 KB |
Output is correct |
28 |
Correct |
26 ms |
496 KB |
Output is correct |
29 |
Correct |
31 ms |
468 KB |
Output is correct |
30 |
Correct |
21 ms |
488 KB |
Output is correct |
31 |
Correct |
21 ms |
620 KB |
Output is correct |
32 |
Correct |
21 ms |
556 KB |
Output is correct |
33 |
Correct |
26 ms |
492 KB |
Output is correct |
34 |
Correct |
22 ms |
504 KB |
Output is correct |
35 |
Correct |
23 ms |
468 KB |
Output is correct |
36 |
Correct |
22 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
340 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
9 ms |
464 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
464 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
13 ms |
556 KB |
Output is correct |
22 |
Correct |
17 ms |
476 KB |
Output is correct |
23 |
Correct |
10 ms |
468 KB |
Output is correct |
24 |
Correct |
29 ms |
480 KB |
Output is correct |
25 |
Correct |
22 ms |
632 KB |
Output is correct |
26 |
Correct |
24 ms |
624 KB |
Output is correct |
27 |
Correct |
24 ms |
504 KB |
Output is correct |
28 |
Correct |
26 ms |
496 KB |
Output is correct |
29 |
Correct |
31 ms |
468 KB |
Output is correct |
30 |
Correct |
21 ms |
488 KB |
Output is correct |
31 |
Correct |
21 ms |
620 KB |
Output is correct |
32 |
Correct |
21 ms |
556 KB |
Output is correct |
33 |
Correct |
26 ms |
492 KB |
Output is correct |
34 |
Correct |
22 ms |
504 KB |
Output is correct |
35 |
Correct |
23 ms |
468 KB |
Output is correct |
36 |
Correct |
22 ms |
468 KB |
Output is correct |
37 |
Correct |
57 ms |
900 KB |
Output is correct |
38 |
Correct |
62 ms |
972 KB |
Output is correct |
39 |
Correct |
67 ms |
596 KB |
Output is correct |
40 |
Correct |
92 ms |
1344 KB |
Output is correct |
41 |
Correct |
80 ms |
752 KB |
Output is correct |
42 |
Correct |
77 ms |
1336 KB |
Output is correct |
43 |
Correct |
86 ms |
1960 KB |
Output is correct |
44 |
Correct |
88 ms |
1960 KB |
Output is correct |
45 |
Correct |
92 ms |
1996 KB |
Output is correct |
46 |
Correct |
73 ms |
460 KB |
Output is correct |
47 |
Correct |
75 ms |
1356 KB |
Output is correct |
48 |
Correct |
83 ms |
1612 KB |
Output is correct |
49 |
Correct |
75 ms |
960 KB |
Output is correct |
50 |
Correct |
81 ms |
1344 KB |
Output is correct |
51 |
Correct |
2 ms |
468 KB |
Output is correct |
52 |
Correct |
107 ms |
2256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
340 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
9 ms |
464 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
464 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
13 ms |
556 KB |
Output is correct |
22 |
Correct |
17 ms |
476 KB |
Output is correct |
23 |
Correct |
10 ms |
468 KB |
Output is correct |
24 |
Correct |
29 ms |
480 KB |
Output is correct |
25 |
Correct |
22 ms |
632 KB |
Output is correct |
26 |
Correct |
24 ms |
624 KB |
Output is correct |
27 |
Correct |
24 ms |
504 KB |
Output is correct |
28 |
Correct |
26 ms |
496 KB |
Output is correct |
29 |
Correct |
31 ms |
468 KB |
Output is correct |
30 |
Correct |
21 ms |
488 KB |
Output is correct |
31 |
Correct |
21 ms |
620 KB |
Output is correct |
32 |
Correct |
21 ms |
556 KB |
Output is correct |
33 |
Correct |
26 ms |
492 KB |
Output is correct |
34 |
Correct |
22 ms |
504 KB |
Output is correct |
35 |
Correct |
23 ms |
468 KB |
Output is correct |
36 |
Correct |
22 ms |
468 KB |
Output is correct |
37 |
Correct |
57 ms |
900 KB |
Output is correct |
38 |
Correct |
62 ms |
972 KB |
Output is correct |
39 |
Correct |
67 ms |
596 KB |
Output is correct |
40 |
Correct |
92 ms |
1344 KB |
Output is correct |
41 |
Correct |
80 ms |
752 KB |
Output is correct |
42 |
Correct |
77 ms |
1336 KB |
Output is correct |
43 |
Correct |
86 ms |
1960 KB |
Output is correct |
44 |
Correct |
88 ms |
1960 KB |
Output is correct |
45 |
Correct |
92 ms |
1996 KB |
Output is correct |
46 |
Correct |
73 ms |
460 KB |
Output is correct |
47 |
Correct |
75 ms |
1356 KB |
Output is correct |
48 |
Correct |
83 ms |
1612 KB |
Output is correct |
49 |
Correct |
75 ms |
960 KB |
Output is correct |
50 |
Correct |
81 ms |
1344 KB |
Output is correct |
51 |
Correct |
2 ms |
468 KB |
Output is correct |
52 |
Correct |
107 ms |
2256 KB |
Output is correct |
53 |
Correct |
109 ms |
1796 KB |
Output is correct |
54 |
Correct |
145 ms |
2088 KB |
Output is correct |
55 |
Correct |
175 ms |
3452 KB |
Output is correct |
56 |
Correct |
114 ms |
2092 KB |
Output is correct |
57 |
Correct |
178 ms |
3660 KB |
Output is correct |
58 |
Correct |
134 ms |
2244 KB |
Output is correct |
59 |
Correct |
148 ms |
2684 KB |
Output is correct |
60 |
Correct |
6 ms |
468 KB |
Output is correct |
61 |
Correct |
153 ms |
2976 KB |
Output is correct |
62 |
Correct |
147 ms |
3272 KB |
Output is correct |
63 |
Correct |
151 ms |
3296 KB |
Output is correct |
64 |
Correct |
151 ms |
3404 KB |
Output is correct |
65 |
Correct |
89 ms |
644 KB |
Output is correct |
66 |
Correct |
83 ms |
924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
340 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
9 ms |
464 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
464 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
13 ms |
556 KB |
Output is correct |
22 |
Correct |
17 ms |
476 KB |
Output is correct |
23 |
Correct |
10 ms |
468 KB |
Output is correct |
24 |
Correct |
29 ms |
480 KB |
Output is correct |
25 |
Correct |
22 ms |
632 KB |
Output is correct |
26 |
Correct |
24 ms |
624 KB |
Output is correct |
27 |
Correct |
24 ms |
504 KB |
Output is correct |
28 |
Correct |
26 ms |
496 KB |
Output is correct |
29 |
Correct |
31 ms |
468 KB |
Output is correct |
30 |
Correct |
21 ms |
488 KB |
Output is correct |
31 |
Correct |
21 ms |
620 KB |
Output is correct |
32 |
Correct |
21 ms |
556 KB |
Output is correct |
33 |
Correct |
26 ms |
492 KB |
Output is correct |
34 |
Correct |
22 ms |
504 KB |
Output is correct |
35 |
Correct |
23 ms |
468 KB |
Output is correct |
36 |
Correct |
22 ms |
468 KB |
Output is correct |
37 |
Correct |
57 ms |
900 KB |
Output is correct |
38 |
Correct |
62 ms |
972 KB |
Output is correct |
39 |
Correct |
67 ms |
596 KB |
Output is correct |
40 |
Correct |
92 ms |
1344 KB |
Output is correct |
41 |
Correct |
80 ms |
752 KB |
Output is correct |
42 |
Correct |
77 ms |
1336 KB |
Output is correct |
43 |
Correct |
86 ms |
1960 KB |
Output is correct |
44 |
Correct |
88 ms |
1960 KB |
Output is correct |
45 |
Correct |
92 ms |
1996 KB |
Output is correct |
46 |
Correct |
73 ms |
460 KB |
Output is correct |
47 |
Correct |
75 ms |
1356 KB |
Output is correct |
48 |
Correct |
83 ms |
1612 KB |
Output is correct |
49 |
Correct |
75 ms |
960 KB |
Output is correct |
50 |
Correct |
81 ms |
1344 KB |
Output is correct |
51 |
Correct |
2 ms |
468 KB |
Output is correct |
52 |
Correct |
107 ms |
2256 KB |
Output is correct |
53 |
Correct |
109 ms |
1796 KB |
Output is correct |
54 |
Correct |
145 ms |
2088 KB |
Output is correct |
55 |
Correct |
175 ms |
3452 KB |
Output is correct |
56 |
Correct |
114 ms |
2092 KB |
Output is correct |
57 |
Correct |
178 ms |
3660 KB |
Output is correct |
58 |
Correct |
134 ms |
2244 KB |
Output is correct |
59 |
Correct |
148 ms |
2684 KB |
Output is correct |
60 |
Correct |
6 ms |
468 KB |
Output is correct |
61 |
Correct |
153 ms |
2976 KB |
Output is correct |
62 |
Correct |
147 ms |
3272 KB |
Output is correct |
63 |
Correct |
151 ms |
3296 KB |
Output is correct |
64 |
Correct |
151 ms |
3404 KB |
Output is correct |
65 |
Correct |
89 ms |
644 KB |
Output is correct |
66 |
Correct |
83 ms |
924 KB |
Output is correct |
67 |
Correct |
187 ms |
2848 KB |
Output is correct |
68 |
Correct |
4 ms |
468 KB |
Output is correct |
69 |
Correct |
378 ms |
6592 KB |
Output is correct |
70 |
Correct |
290 ms |
4240 KB |
Output is correct |
71 |
Correct |
284 ms |
4148 KB |
Output is correct |
72 |
Correct |
261 ms |
852 KB |
Output is correct |
73 |
Correct |
260 ms |
852 KB |
Output is correct |
74 |
Correct |
378 ms |
7104 KB |
Output is correct |
75 |
Correct |
339 ms |
5624 KB |
Output is correct |
76 |
Correct |
389 ms |
6792 KB |
Output is correct |
77 |
Correct |
401 ms |
7280 KB |
Output is correct |