//君の手を握ってしまったら
//孤独を知らないこの街には
//もう二度と帰ってくることはできないのでしょう
//君が手を差し伸べた 光で影が生まれる
//歌って聞かせて この話の続き
//連れて行って見たことない星まで
//さユリ - 花の塔
#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> tans[n], ans;
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;
tans[j].pb(t), ans.pb(t);
}
}
}
}
set<int> tst[n], st;
for(auto x:ans) st.insert(x);
for(int i = 0; i < n; ++i){
for(int x:tans[i]) tst[i].insert(x);
set<int> tmp;
for(auto x:st) if(tst[i].find(x) != tst[i].end()) tmp.insert(x);
st = tmp;
}
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 |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
596 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 |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
608 KB |
Output is correct |
14 |
Correct |
9 ms |
624 KB |
Output is correct |
15 |
Correct |
6 ms |
596 KB |
Output is correct |
16 |
Correct |
9 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
6 ms |
612 KB |
Output is correct |
19 |
Correct |
5 ms |
596 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 |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
608 KB |
Output is correct |
14 |
Correct |
9 ms |
624 KB |
Output is correct |
15 |
Correct |
6 ms |
596 KB |
Output is correct |
16 |
Correct |
9 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
6 ms |
612 KB |
Output is correct |
19 |
Correct |
5 ms |
596 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
49 ms |
6152 KB |
Output is correct |
22 |
Correct |
53 ms |
7480 KB |
Output is correct |
23 |
Correct |
26 ms |
3784 KB |
Output is correct |
24 |
Correct |
92 ms |
12928 KB |
Output is correct |
25 |
Correct |
120 ms |
18888 KB |
Output is correct |
26 |
Correct |
145 ms |
21516 KB |
Output is correct |
27 |
Correct |
90 ms |
11612 KB |
Output is correct |
28 |
Correct |
74 ms |
10472 KB |
Output is correct |
29 |
Correct |
77 ms |
13404 KB |
Output is correct |
30 |
Correct |
64 ms |
15296 KB |
Output is correct |
31 |
Correct |
140 ms |
20828 KB |
Output is correct |
32 |
Correct |
96 ms |
14140 KB |
Output is correct |
33 |
Correct |
22 ms |
744 KB |
Output is correct |
34 |
Correct |
22 ms |
748 KB |
Output is correct |
35 |
Correct |
68 ms |
11128 KB |
Output is correct |
36 |
Correct |
94 ms |
13888 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 |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
608 KB |
Output is correct |
14 |
Correct |
9 ms |
624 KB |
Output is correct |
15 |
Correct |
6 ms |
596 KB |
Output is correct |
16 |
Correct |
9 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
6 ms |
612 KB |
Output is correct |
19 |
Correct |
5 ms |
596 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
49 ms |
6152 KB |
Output is correct |
22 |
Correct |
53 ms |
7480 KB |
Output is correct |
23 |
Correct |
26 ms |
3784 KB |
Output is correct |
24 |
Correct |
92 ms |
12928 KB |
Output is correct |
25 |
Correct |
120 ms |
18888 KB |
Output is correct |
26 |
Correct |
145 ms |
21516 KB |
Output is correct |
27 |
Correct |
90 ms |
11612 KB |
Output is correct |
28 |
Correct |
74 ms |
10472 KB |
Output is correct |
29 |
Correct |
77 ms |
13404 KB |
Output is correct |
30 |
Correct |
64 ms |
15296 KB |
Output is correct |
31 |
Correct |
140 ms |
20828 KB |
Output is correct |
32 |
Correct |
96 ms |
14140 KB |
Output is correct |
33 |
Correct |
22 ms |
744 KB |
Output is correct |
34 |
Correct |
22 ms |
748 KB |
Output is correct |
35 |
Correct |
68 ms |
11128 KB |
Output is correct |
36 |
Correct |
94 ms |
13888 KB |
Output is correct |
37 |
Correct |
797 ms |
107132 KB |
Output is correct |
38 |
Correct |
819 ms |
109772 KB |
Output is correct |
39 |
Correct |
75 ms |
2072 KB |
Output is correct |
40 |
Execution timed out |
1098 ms |
149468 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
608 KB |
Output is correct |
14 |
Correct |
9 ms |
624 KB |
Output is correct |
15 |
Correct |
6 ms |
596 KB |
Output is correct |
16 |
Correct |
9 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
6 ms |
612 KB |
Output is correct |
19 |
Correct |
5 ms |
596 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
49 ms |
6152 KB |
Output is correct |
22 |
Correct |
53 ms |
7480 KB |
Output is correct |
23 |
Correct |
26 ms |
3784 KB |
Output is correct |
24 |
Correct |
92 ms |
12928 KB |
Output is correct |
25 |
Correct |
120 ms |
18888 KB |
Output is correct |
26 |
Correct |
145 ms |
21516 KB |
Output is correct |
27 |
Correct |
90 ms |
11612 KB |
Output is correct |
28 |
Correct |
74 ms |
10472 KB |
Output is correct |
29 |
Correct |
77 ms |
13404 KB |
Output is correct |
30 |
Correct |
64 ms |
15296 KB |
Output is correct |
31 |
Correct |
140 ms |
20828 KB |
Output is correct |
32 |
Correct |
96 ms |
14140 KB |
Output is correct |
33 |
Correct |
22 ms |
744 KB |
Output is correct |
34 |
Correct |
22 ms |
748 KB |
Output is correct |
35 |
Correct |
68 ms |
11128 KB |
Output is correct |
36 |
Correct |
94 ms |
13888 KB |
Output is correct |
37 |
Correct |
797 ms |
107132 KB |
Output is correct |
38 |
Correct |
819 ms |
109772 KB |
Output is correct |
39 |
Correct |
75 ms |
2072 KB |
Output is correct |
40 |
Execution timed out |
1098 ms |
149468 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
608 KB |
Output is correct |
14 |
Correct |
9 ms |
624 KB |
Output is correct |
15 |
Correct |
6 ms |
596 KB |
Output is correct |
16 |
Correct |
9 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
6 ms |
612 KB |
Output is correct |
19 |
Correct |
5 ms |
596 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
49 ms |
6152 KB |
Output is correct |
22 |
Correct |
53 ms |
7480 KB |
Output is correct |
23 |
Correct |
26 ms |
3784 KB |
Output is correct |
24 |
Correct |
92 ms |
12928 KB |
Output is correct |
25 |
Correct |
120 ms |
18888 KB |
Output is correct |
26 |
Correct |
145 ms |
21516 KB |
Output is correct |
27 |
Correct |
90 ms |
11612 KB |
Output is correct |
28 |
Correct |
74 ms |
10472 KB |
Output is correct |
29 |
Correct |
77 ms |
13404 KB |
Output is correct |
30 |
Correct |
64 ms |
15296 KB |
Output is correct |
31 |
Correct |
140 ms |
20828 KB |
Output is correct |
32 |
Correct |
96 ms |
14140 KB |
Output is correct |
33 |
Correct |
22 ms |
744 KB |
Output is correct |
34 |
Correct |
22 ms |
748 KB |
Output is correct |
35 |
Correct |
68 ms |
11128 KB |
Output is correct |
36 |
Correct |
94 ms |
13888 KB |
Output is correct |
37 |
Correct |
797 ms |
107132 KB |
Output is correct |
38 |
Correct |
819 ms |
109772 KB |
Output is correct |
39 |
Correct |
75 ms |
2072 KB |
Output is correct |
40 |
Execution timed out |
1098 ms |
149468 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |