//君の手を握ってしまったら
//孤独を知らないこの街には
//もう二度と帰ってくることはできないのでしょう
//君が手を差し伸べた 光で影が生まれる
//歌って聞かせて この話の続き
//連れて行って見たことない星まで
//さユリ - 花の塔
#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());
vector<vector<int>> dp(2, vector<int>(sum + 1, 0));
dp[0][0] = 1;
for(int i = 0; i < n; ++i){
dp[1].assign(sum + 1, 0);
for(int j = 0; j <= sum; ++j){
dp[1][j] |= dp[0][j];
if(j >= v[i]) dp[1][j] |= dp[0][j - v[i]];
}
dp[0] = dp[1];
}
if(sum % 2 == 1 || dp[1][sum / 2] == 0){
cout << "0\n";
return;
}
set<int> tans[n], ans;
for(int k = 0; k < n; ++k){
dp[0].assign(sum - v[k] + 1, 0);
dp[1].assign(sum - v[k] + 1, 0);
dp[0][0] = 1;
for(int i = 0; i < n; ++i){
if(i == k) continue;
dp[1].assign(sum + 1, 0);
for(int j = 0; j <= sum - v[k]; ++j){
dp[1][j] |= dp[0][j];
if(j >= v[i]) dp[1][j] |= dp[0][j - v[i]];
}
dp[0] = dp[1];
}
for(int val = sum - v[k]; val >= 0; --val){
if(dp[1][val]) {
int t = val - (sum - val - v[k]);
if(t <= 0) break;
tans[k].insert(t), ans.insert(t);
}
}
}
for(int i = 0; i < n; ++i){
set<int> tmp;
for(auto x:ans) if(tans[i].find(x) != tans[i].end()) tmp.insert(x);
ans = tmp;
}
cout << ans.size() << '\n';
for(auto x:ans) cout << x << ' ';
}
signed main(){
starburst
int t = 1; //cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
63 ms |
5148 KB |
Output is correct |
22 |
Correct |
77 ms |
6336 KB |
Output is correct |
23 |
Correct |
28 ms |
3084 KB |
Output is correct |
24 |
Correct |
145 ms |
10652 KB |
Output is correct |
25 |
Correct |
260 ms |
16176 KB |
Output is correct |
26 |
Correct |
295 ms |
18556 KB |
Output is correct |
27 |
Correct |
223 ms |
9968 KB |
Output is correct |
28 |
Correct |
263 ms |
9036 KB |
Output is correct |
29 |
Correct |
268 ms |
11292 KB |
Output is correct |
30 |
Correct |
179 ms |
12984 KB |
Output is correct |
31 |
Correct |
256 ms |
17776 KB |
Output is correct |
32 |
Correct |
163 ms |
11604 KB |
Output is correct |
33 |
Correct |
183 ms |
676 KB |
Output is correct |
34 |
Correct |
187 ms |
820 KB |
Output is correct |
35 |
Correct |
223 ms |
9788 KB |
Output is correct |
36 |
Correct |
157 ms |
11340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
63 ms |
5148 KB |
Output is correct |
22 |
Correct |
77 ms |
6336 KB |
Output is correct |
23 |
Correct |
28 ms |
3084 KB |
Output is correct |
24 |
Correct |
145 ms |
10652 KB |
Output is correct |
25 |
Correct |
260 ms |
16176 KB |
Output is correct |
26 |
Correct |
295 ms |
18556 KB |
Output is correct |
27 |
Correct |
223 ms |
9968 KB |
Output is correct |
28 |
Correct |
263 ms |
9036 KB |
Output is correct |
29 |
Correct |
268 ms |
11292 KB |
Output is correct |
30 |
Correct |
179 ms |
12984 KB |
Output is correct |
31 |
Correct |
256 ms |
17776 KB |
Output is correct |
32 |
Correct |
163 ms |
11604 KB |
Output is correct |
33 |
Correct |
183 ms |
676 KB |
Output is correct |
34 |
Correct |
187 ms |
820 KB |
Output is correct |
35 |
Correct |
223 ms |
9788 KB |
Output is correct |
36 |
Correct |
157 ms |
11340 KB |
Output is correct |
37 |
Execution timed out |
1087 ms |
55472 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
63 ms |
5148 KB |
Output is correct |
22 |
Correct |
77 ms |
6336 KB |
Output is correct |
23 |
Correct |
28 ms |
3084 KB |
Output is correct |
24 |
Correct |
145 ms |
10652 KB |
Output is correct |
25 |
Correct |
260 ms |
16176 KB |
Output is correct |
26 |
Correct |
295 ms |
18556 KB |
Output is correct |
27 |
Correct |
223 ms |
9968 KB |
Output is correct |
28 |
Correct |
263 ms |
9036 KB |
Output is correct |
29 |
Correct |
268 ms |
11292 KB |
Output is correct |
30 |
Correct |
179 ms |
12984 KB |
Output is correct |
31 |
Correct |
256 ms |
17776 KB |
Output is correct |
32 |
Correct |
163 ms |
11604 KB |
Output is correct |
33 |
Correct |
183 ms |
676 KB |
Output is correct |
34 |
Correct |
187 ms |
820 KB |
Output is correct |
35 |
Correct |
223 ms |
9788 KB |
Output is correct |
36 |
Correct |
157 ms |
11340 KB |
Output is correct |
37 |
Execution timed out |
1087 ms |
55472 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
63 ms |
5148 KB |
Output is correct |
22 |
Correct |
77 ms |
6336 KB |
Output is correct |
23 |
Correct |
28 ms |
3084 KB |
Output is correct |
24 |
Correct |
145 ms |
10652 KB |
Output is correct |
25 |
Correct |
260 ms |
16176 KB |
Output is correct |
26 |
Correct |
295 ms |
18556 KB |
Output is correct |
27 |
Correct |
223 ms |
9968 KB |
Output is correct |
28 |
Correct |
263 ms |
9036 KB |
Output is correct |
29 |
Correct |
268 ms |
11292 KB |
Output is correct |
30 |
Correct |
179 ms |
12984 KB |
Output is correct |
31 |
Correct |
256 ms |
17776 KB |
Output is correct |
32 |
Correct |
163 ms |
11604 KB |
Output is correct |
33 |
Correct |
183 ms |
676 KB |
Output is correct |
34 |
Correct |
187 ms |
820 KB |
Output is correct |
35 |
Correct |
223 ms |
9788 KB |
Output is correct |
36 |
Correct |
157 ms |
11340 KB |
Output is correct |
37 |
Execution timed out |
1087 ms |
55472 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |