#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int MOD = (int) 1e9 + 7;
const int MAXN = 500;
int arr[MAXN + 1];
int dp[MAXN * MAXN + 1];
inline void mod(int &x) {
if(x >= MOD)
x -= MOD;
}
int fr[MAXN * MAXN + 1];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, j, n;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
dp[0] = 1;
int sum = 0;
for(i = 1; i <= n; i++) {
cin >> arr[i];
for(j = sum; j >= 0; j--) {
dp[j + arr[i]] += dp[j];
mod(dp[j + arr[i]]);
}
sum += arr[i];
}
if(dp[sum / 2] == 0) {
cout << 0;
return 0;
}
for(i = n; i >= 1; i--) {
for(j = arr[i]; j <= sum; j++) {
dp[j] -= dp[j - arr[i]] - MOD;
mod(dp[j]);
}
if(i < n) {
for(j = sum; j >= arr[i + 1]; j--) {
dp[j] += dp[j - arr[i + 1]];
mod(dp[j]);
}
}
for(j = 0; j <= sum; j++) {
if(dp[j] > 0) {
int x = 2 * j - sum + arr[i];
if(x >= 0 && x <= sum) {
fr[x]++;
}
}
}
}
int ans = 0;
for(i = 1; i <= sum; i++) {
if(fr[i] == n) {
ans++;
}
}
cout << ans << "\n";
for(i = 0; i <= sum; i++) {
if(fr[i] == n) {
cout << i << " ";
}
}
//cin.close();
//cout.close();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
2 ms |
668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
2 ms |
668 KB |
Output is correct |
10 |
Correct |
2 ms |
668 KB |
Output is correct |
11 |
Correct |
2 ms |
668 KB |
Output is correct |
12 |
Correct |
2 ms |
668 KB |
Output is correct |
13 |
Correct |
2 ms |
668 KB |
Output is correct |
14 |
Correct |
2 ms |
668 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
856 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
2 ms |
668 KB |
Output is correct |
10 |
Correct |
2 ms |
668 KB |
Output is correct |
11 |
Correct |
2 ms |
668 KB |
Output is correct |
12 |
Correct |
2 ms |
668 KB |
Output is correct |
13 |
Correct |
2 ms |
668 KB |
Output is correct |
14 |
Correct |
2 ms |
668 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
856 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Correct |
3 ms |
856 KB |
Output is correct |
22 |
Correct |
3 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
3 ms |
860 KB |
Output is correct |
25 |
Correct |
5 ms |
924 KB |
Output is correct |
26 |
Correct |
6 ms |
924 KB |
Output is correct |
27 |
Correct |
6 ms |
924 KB |
Output is correct |
28 |
Correct |
7 ms |
924 KB |
Output is correct |
29 |
Correct |
6 ms |
936 KB |
Output is correct |
30 |
Correct |
3 ms |
936 KB |
Output is correct |
31 |
Correct |
5 ms |
936 KB |
Output is correct |
32 |
Correct |
4 ms |
936 KB |
Output is correct |
33 |
Correct |
5 ms |
936 KB |
Output is correct |
34 |
Correct |
5 ms |
936 KB |
Output is correct |
35 |
Correct |
7 ms |
944 KB |
Output is correct |
36 |
Correct |
4 ms |
976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
2 ms |
668 KB |
Output is correct |
10 |
Correct |
2 ms |
668 KB |
Output is correct |
11 |
Correct |
2 ms |
668 KB |
Output is correct |
12 |
Correct |
2 ms |
668 KB |
Output is correct |
13 |
Correct |
2 ms |
668 KB |
Output is correct |
14 |
Correct |
2 ms |
668 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
856 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Correct |
3 ms |
856 KB |
Output is correct |
22 |
Correct |
3 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
3 ms |
860 KB |
Output is correct |
25 |
Correct |
5 ms |
924 KB |
Output is correct |
26 |
Correct |
6 ms |
924 KB |
Output is correct |
27 |
Correct |
6 ms |
924 KB |
Output is correct |
28 |
Correct |
7 ms |
924 KB |
Output is correct |
29 |
Correct |
6 ms |
936 KB |
Output is correct |
30 |
Correct |
3 ms |
936 KB |
Output is correct |
31 |
Correct |
5 ms |
936 KB |
Output is correct |
32 |
Correct |
4 ms |
936 KB |
Output is correct |
33 |
Correct |
5 ms |
936 KB |
Output is correct |
34 |
Correct |
5 ms |
936 KB |
Output is correct |
35 |
Correct |
7 ms |
944 KB |
Output is correct |
36 |
Correct |
4 ms |
976 KB |
Output is correct |
37 |
Correct |
15 ms |
1056 KB |
Output is correct |
38 |
Correct |
16 ms |
1108 KB |
Output is correct |
39 |
Correct |
52 ms |
1320 KB |
Output is correct |
40 |
Correct |
33 ms |
1320 KB |
Output is correct |
41 |
Correct |
65 ms |
1456 KB |
Output is correct |
42 |
Correct |
28 ms |
1456 KB |
Output is correct |
43 |
Correct |
50 ms |
1524 KB |
Output is correct |
44 |
Correct |
54 ms |
1524 KB |
Output is correct |
45 |
Correct |
55 ms |
1524 KB |
Output is correct |
46 |
Correct |
47 ms |
1524 KB |
Output is correct |
47 |
Correct |
31 ms |
1524 KB |
Output is correct |
48 |
Correct |
63 ms |
1524 KB |
Output is correct |
49 |
Correct |
73 ms |
1544 KB |
Output is correct |
50 |
Correct |
31 ms |
1544 KB |
Output is correct |
51 |
Correct |
30 ms |
1544 KB |
Output is correct |
52 |
Correct |
74 ms |
1780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
2 ms |
668 KB |
Output is correct |
10 |
Correct |
2 ms |
668 KB |
Output is correct |
11 |
Correct |
2 ms |
668 KB |
Output is correct |
12 |
Correct |
2 ms |
668 KB |
Output is correct |
13 |
Correct |
2 ms |
668 KB |
Output is correct |
14 |
Correct |
2 ms |
668 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
856 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Correct |
3 ms |
856 KB |
Output is correct |
22 |
Correct |
3 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
3 ms |
860 KB |
Output is correct |
25 |
Correct |
5 ms |
924 KB |
Output is correct |
26 |
Correct |
6 ms |
924 KB |
Output is correct |
27 |
Correct |
6 ms |
924 KB |
Output is correct |
28 |
Correct |
7 ms |
924 KB |
Output is correct |
29 |
Correct |
6 ms |
936 KB |
Output is correct |
30 |
Correct |
3 ms |
936 KB |
Output is correct |
31 |
Correct |
5 ms |
936 KB |
Output is correct |
32 |
Correct |
4 ms |
936 KB |
Output is correct |
33 |
Correct |
5 ms |
936 KB |
Output is correct |
34 |
Correct |
5 ms |
936 KB |
Output is correct |
35 |
Correct |
7 ms |
944 KB |
Output is correct |
36 |
Correct |
4 ms |
976 KB |
Output is correct |
37 |
Correct |
15 ms |
1056 KB |
Output is correct |
38 |
Correct |
16 ms |
1108 KB |
Output is correct |
39 |
Correct |
52 ms |
1320 KB |
Output is correct |
40 |
Correct |
33 ms |
1320 KB |
Output is correct |
41 |
Correct |
65 ms |
1456 KB |
Output is correct |
42 |
Correct |
28 ms |
1456 KB |
Output is correct |
43 |
Correct |
50 ms |
1524 KB |
Output is correct |
44 |
Correct |
54 ms |
1524 KB |
Output is correct |
45 |
Correct |
55 ms |
1524 KB |
Output is correct |
46 |
Correct |
47 ms |
1524 KB |
Output is correct |
47 |
Correct |
31 ms |
1524 KB |
Output is correct |
48 |
Correct |
63 ms |
1524 KB |
Output is correct |
49 |
Correct |
73 ms |
1544 KB |
Output is correct |
50 |
Correct |
31 ms |
1544 KB |
Output is correct |
51 |
Correct |
30 ms |
1544 KB |
Output is correct |
52 |
Correct |
74 ms |
1780 KB |
Output is correct |
53 |
Correct |
51 ms |
1780 KB |
Output is correct |
54 |
Correct |
69 ms |
1780 KB |
Output is correct |
55 |
Correct |
146 ms |
2164 KB |
Output is correct |
56 |
Correct |
65 ms |
2164 KB |
Output is correct |
57 |
Correct |
149 ms |
2308 KB |
Output is correct |
58 |
Correct |
77 ms |
2308 KB |
Output is correct |
59 |
Correct |
100 ms |
2308 KB |
Output is correct |
60 |
Correct |
75 ms |
2308 KB |
Output is correct |
61 |
Correct |
105 ms |
2308 KB |
Output is correct |
62 |
Correct |
116 ms |
2308 KB |
Output is correct |
63 |
Correct |
127 ms |
2308 KB |
Output is correct |
64 |
Correct |
121 ms |
2308 KB |
Output is correct |
65 |
Correct |
59 ms |
2308 KB |
Output is correct |
66 |
Correct |
73 ms |
2308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
2 ms |
668 KB |
Output is correct |
10 |
Correct |
2 ms |
668 KB |
Output is correct |
11 |
Correct |
2 ms |
668 KB |
Output is correct |
12 |
Correct |
2 ms |
668 KB |
Output is correct |
13 |
Correct |
2 ms |
668 KB |
Output is correct |
14 |
Correct |
2 ms |
668 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
856 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Correct |
3 ms |
856 KB |
Output is correct |
22 |
Correct |
3 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
3 ms |
860 KB |
Output is correct |
25 |
Correct |
5 ms |
924 KB |
Output is correct |
26 |
Correct |
6 ms |
924 KB |
Output is correct |
27 |
Correct |
6 ms |
924 KB |
Output is correct |
28 |
Correct |
7 ms |
924 KB |
Output is correct |
29 |
Correct |
6 ms |
936 KB |
Output is correct |
30 |
Correct |
3 ms |
936 KB |
Output is correct |
31 |
Correct |
5 ms |
936 KB |
Output is correct |
32 |
Correct |
4 ms |
936 KB |
Output is correct |
33 |
Correct |
5 ms |
936 KB |
Output is correct |
34 |
Correct |
5 ms |
936 KB |
Output is correct |
35 |
Correct |
7 ms |
944 KB |
Output is correct |
36 |
Correct |
4 ms |
976 KB |
Output is correct |
37 |
Correct |
15 ms |
1056 KB |
Output is correct |
38 |
Correct |
16 ms |
1108 KB |
Output is correct |
39 |
Correct |
52 ms |
1320 KB |
Output is correct |
40 |
Correct |
33 ms |
1320 KB |
Output is correct |
41 |
Correct |
65 ms |
1456 KB |
Output is correct |
42 |
Correct |
28 ms |
1456 KB |
Output is correct |
43 |
Correct |
50 ms |
1524 KB |
Output is correct |
44 |
Correct |
54 ms |
1524 KB |
Output is correct |
45 |
Correct |
55 ms |
1524 KB |
Output is correct |
46 |
Correct |
47 ms |
1524 KB |
Output is correct |
47 |
Correct |
31 ms |
1524 KB |
Output is correct |
48 |
Correct |
63 ms |
1524 KB |
Output is correct |
49 |
Correct |
73 ms |
1544 KB |
Output is correct |
50 |
Correct |
31 ms |
1544 KB |
Output is correct |
51 |
Correct |
30 ms |
1544 KB |
Output is correct |
52 |
Correct |
74 ms |
1780 KB |
Output is correct |
53 |
Correct |
51 ms |
1780 KB |
Output is correct |
54 |
Correct |
69 ms |
1780 KB |
Output is correct |
55 |
Correct |
146 ms |
2164 KB |
Output is correct |
56 |
Correct |
65 ms |
2164 KB |
Output is correct |
57 |
Correct |
149 ms |
2308 KB |
Output is correct |
58 |
Correct |
77 ms |
2308 KB |
Output is correct |
59 |
Correct |
100 ms |
2308 KB |
Output is correct |
60 |
Correct |
75 ms |
2308 KB |
Output is correct |
61 |
Correct |
105 ms |
2308 KB |
Output is correct |
62 |
Correct |
116 ms |
2308 KB |
Output is correct |
63 |
Correct |
127 ms |
2308 KB |
Output is correct |
64 |
Correct |
121 ms |
2308 KB |
Output is correct |
65 |
Correct |
59 ms |
2308 KB |
Output is correct |
66 |
Correct |
73 ms |
2308 KB |
Output is correct |
67 |
Correct |
108 ms |
2308 KB |
Output is correct |
68 |
Correct |
28 ms |
2308 KB |
Output is correct |
69 |
Correct |
376 ms |
3264 KB |
Output is correct |
70 |
Correct |
236 ms |
3264 KB |
Output is correct |
71 |
Correct |
230 ms |
3264 KB |
Output is correct |
72 |
Correct |
218 ms |
3264 KB |
Output is correct |
73 |
Correct |
218 ms |
3264 KB |
Output is correct |
74 |
Correct |
419 ms |
3532 KB |
Output is correct |
75 |
Correct |
314 ms |
3532 KB |
Output is correct |
76 |
Correct |
478 ms |
3796 KB |
Output is correct |
77 |
Correct |
428 ms |
3796 KB |
Output is correct |