#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 1e2 + 5;
const ll shift = 2e6;
const ll mod = 1e9 + 7;
const ll M = 10000 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll block = 500;
const double eps = 1e-10;
int n, a[N], dp[M], acc = 0, cnt[M];
int main(){
speed;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
acc += a[i];
}
dp[0] = 1;
for(int i = 1; i <= n; i++){
for(int sum = M - 5; sum >= 0; sum--){
if(sum - a[i] >= 0 && dp[sum - a[i]])
dp[sum] = 1;
}
}
if(acc % 2 != 0 || dp[acc / 2] == 0){
cout << 0 << endl;
return 0;
}
for(int i = 1; i <= n; i++){
memset(dp, 0, sizeof(dp));
dp[0] = 1;
acc -= a[i];
for(int j = 1; j <= n; j++){
if(j == i)
continue;
for(int sum = M - 5; sum >= 0; sum--){
if(sum - a[j] >= 0 && dp[sum - a[j]])
dp[sum] = 1;
}
}
for(int sum = 0; sum <= M - 5; sum++){
if(dp[sum]){
int ost = acc - sum;
if(ost - sum < 0)
continue;
cnt[ost - sum]++;
}
}
acc += a[i];
}
vector <int> ans;
for(int i = 0; i <= M - 5; i++){
if(cnt[i] == n)
ans.pb(i);
}
cout << ans.size() << endl;
for(auto to : ans)
cout << to << " ";
}
/*
%I64d
%I64d
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
356 KB |
Output is correct |
12 |
Correct |
7 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
332 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
7 ms |
316 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
5 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
312 KB |
Output is correct |
20 |
Correct |
7 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
356 KB |
Output is correct |
12 |
Correct |
7 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
332 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
7 ms |
316 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
5 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
312 KB |
Output is correct |
20 |
Correct |
7 ms |
332 KB |
Output is correct |
21 |
Correct |
31 ms |
348 KB |
Output is correct |
22 |
Correct |
41 ms |
332 KB |
Output is correct |
23 |
Correct |
20 ms |
352 KB |
Output is correct |
24 |
Correct |
68 ms |
360 KB |
Output is correct |
25 |
Correct |
78 ms |
372 KB |
Output is correct |
26 |
Correct |
96 ms |
372 KB |
Output is correct |
27 |
Correct |
88 ms |
452 KB |
Output is correct |
28 |
Correct |
105 ms |
376 KB |
Output is correct |
29 |
Correct |
92 ms |
332 KB |
Output is correct |
30 |
Correct |
76 ms |
356 KB |
Output is correct |
31 |
Correct |
83 ms |
376 KB |
Output is correct |
32 |
Correct |
82 ms |
364 KB |
Output is correct |
33 |
Correct |
84 ms |
452 KB |
Output is correct |
34 |
Correct |
91 ms |
368 KB |
Output is correct |
35 |
Correct |
88 ms |
332 KB |
Output is correct |
36 |
Correct |
77 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
356 KB |
Output is correct |
12 |
Correct |
7 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
332 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
7 ms |
316 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
5 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
312 KB |
Output is correct |
20 |
Correct |
7 ms |
332 KB |
Output is correct |
21 |
Correct |
31 ms |
348 KB |
Output is correct |
22 |
Correct |
41 ms |
332 KB |
Output is correct |
23 |
Correct |
20 ms |
352 KB |
Output is correct |
24 |
Correct |
68 ms |
360 KB |
Output is correct |
25 |
Correct |
78 ms |
372 KB |
Output is correct |
26 |
Correct |
96 ms |
372 KB |
Output is correct |
27 |
Correct |
88 ms |
452 KB |
Output is correct |
28 |
Correct |
105 ms |
376 KB |
Output is correct |
29 |
Correct |
92 ms |
332 KB |
Output is correct |
30 |
Correct |
76 ms |
356 KB |
Output is correct |
31 |
Correct |
83 ms |
376 KB |
Output is correct |
32 |
Correct |
82 ms |
364 KB |
Output is correct |
33 |
Correct |
84 ms |
452 KB |
Output is correct |
34 |
Correct |
91 ms |
368 KB |
Output is correct |
35 |
Correct |
88 ms |
332 KB |
Output is correct |
36 |
Correct |
77 ms |
332 KB |
Output is correct |
37 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
356 KB |
Output is correct |
12 |
Correct |
7 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
332 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
7 ms |
316 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
5 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
312 KB |
Output is correct |
20 |
Correct |
7 ms |
332 KB |
Output is correct |
21 |
Correct |
31 ms |
348 KB |
Output is correct |
22 |
Correct |
41 ms |
332 KB |
Output is correct |
23 |
Correct |
20 ms |
352 KB |
Output is correct |
24 |
Correct |
68 ms |
360 KB |
Output is correct |
25 |
Correct |
78 ms |
372 KB |
Output is correct |
26 |
Correct |
96 ms |
372 KB |
Output is correct |
27 |
Correct |
88 ms |
452 KB |
Output is correct |
28 |
Correct |
105 ms |
376 KB |
Output is correct |
29 |
Correct |
92 ms |
332 KB |
Output is correct |
30 |
Correct |
76 ms |
356 KB |
Output is correct |
31 |
Correct |
83 ms |
376 KB |
Output is correct |
32 |
Correct |
82 ms |
364 KB |
Output is correct |
33 |
Correct |
84 ms |
452 KB |
Output is correct |
34 |
Correct |
91 ms |
368 KB |
Output is correct |
35 |
Correct |
88 ms |
332 KB |
Output is correct |
36 |
Correct |
77 ms |
332 KB |
Output is correct |
37 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
356 KB |
Output is correct |
12 |
Correct |
7 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
332 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
7 ms |
316 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
5 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
312 KB |
Output is correct |
20 |
Correct |
7 ms |
332 KB |
Output is correct |
21 |
Correct |
31 ms |
348 KB |
Output is correct |
22 |
Correct |
41 ms |
332 KB |
Output is correct |
23 |
Correct |
20 ms |
352 KB |
Output is correct |
24 |
Correct |
68 ms |
360 KB |
Output is correct |
25 |
Correct |
78 ms |
372 KB |
Output is correct |
26 |
Correct |
96 ms |
372 KB |
Output is correct |
27 |
Correct |
88 ms |
452 KB |
Output is correct |
28 |
Correct |
105 ms |
376 KB |
Output is correct |
29 |
Correct |
92 ms |
332 KB |
Output is correct |
30 |
Correct |
76 ms |
356 KB |
Output is correct |
31 |
Correct |
83 ms |
376 KB |
Output is correct |
32 |
Correct |
82 ms |
364 KB |
Output is correct |
33 |
Correct |
84 ms |
452 KB |
Output is correct |
34 |
Correct |
91 ms |
368 KB |
Output is correct |
35 |
Correct |
88 ms |
332 KB |
Output is correct |
36 |
Correct |
77 ms |
332 KB |
Output is correct |
37 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
38 |
Halted |
0 ms |
0 KB |
- |