#include <stdio.h>
#define N 500
#define A 500
#define S (N * A)
#define L 60
#define K (S / L + 1)
int aa[N], kk[S + 1], n;
long long dp[N + 1][K]; int n_;
void add(int a) {
int h, q, r;
q = a / L, r = a % L;
n_++;
for (h = 0; h < K; h++) {
dp[n_][h] = dp[n_ - 1][h];
if (h >= q)
dp[n_][h] |= (dp[n_ - 1][h - q] & (1LL << (L - r)) - 1) << r;
if (h >= q + 1)
dp[n_][h] |= dp[n_ - 1][h - q - 1] >> (L - r);
}
}
void solve(int l, int r) {
int m, i, s, sum;
if (l == r) {
sum = 0;
for (i = 0; i < n; i++)
if (i != l)
sum += aa[i];
for (s = 0; s * 2 <= sum; s++)
if ((dp[n_][s / L] & 1LL << s % L) != 0)
kk[sum - s * 2]++;
return;
}
m = (l + r) / 2;
for (i = m + 1; i <= r; i++)
add(aa[i]);
solve(l, m);
n_ -= r - m;
for (i = l; i <= m; i++)
add(aa[i]);
solve(m + 1, r);
n_ -= m - l + 1;
}
int main() {
int i, sum, a, k;
scanf("%d", &n);
sum = 0;
for (i = 0; i < n; i++) {
scanf("%d", &aa[i]);
sum += aa[i];
}
if (sum % 2 != 0) {
printf("0\n\n");
return 0;
}
dp[0][0] = 1, n_ = 0;
for (i = 0; i < n; i++)
add(aa[i]);
if ((dp[n_][sum / 2 / L] & 1LL << sum / 2 % L) == 0) {
printf("0\n\n");
return 0;
}
n_ = 0, solve(0, n - 1);
k = 0;
for (a = 1; a <= S; a++)
if (kk[a] == n)
k++;
printf("%d\n", k);
for (a = 1; a <= S; a++)
if (kk[a] == n)
printf("%d ", a);
printf("\n");
return 0;
}
Compilation message
bootfall.c: In function 'add':
bootfall.c:20:55: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
20 | dp[n_][h] |= (dp[n_ - 1][h - q] & (1LL << (L - r)) - 1) << r;
| ~~~~~~~~~~~~~~~~~^~~
bootfall.c: In function 'main':
bootfall.c:53:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
bootfall.c:56:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
424 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
1 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
424 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
1 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
1184 KB |
Output is correct |
11 |
Correct |
2 ms |
1188 KB |
Output is correct |
12 |
Correct |
2 ms |
1236 KB |
Output is correct |
13 |
Correct |
3 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
2 ms |
1108 KB |
Output is correct |
16 |
Correct |
2 ms |
1236 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
1060 KB |
Output is correct |
19 |
Correct |
2 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
424 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
1 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
1184 KB |
Output is correct |
11 |
Correct |
2 ms |
1188 KB |
Output is correct |
12 |
Correct |
2 ms |
1236 KB |
Output is correct |
13 |
Correct |
3 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
2 ms |
1108 KB |
Output is correct |
16 |
Correct |
2 ms |
1236 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
1060 KB |
Output is correct |
19 |
Correct |
2 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1204 KB |
Output is correct |
21 |
Correct |
5 ms |
2388 KB |
Output is correct |
22 |
Correct |
5 ms |
2644 KB |
Output is correct |
23 |
Correct |
4 ms |
1876 KB |
Output is correct |
24 |
Correct |
7 ms |
3388 KB |
Output is correct |
25 |
Correct |
7 ms |
3412 KB |
Output is correct |
26 |
Correct |
8 ms |
3600 KB |
Output is correct |
27 |
Correct |
8 ms |
3604 KB |
Output is correct |
28 |
Correct |
8 ms |
3492 KB |
Output is correct |
29 |
Correct |
8 ms |
3492 KB |
Output is correct |
30 |
Correct |
8 ms |
3588 KB |
Output is correct |
31 |
Correct |
8 ms |
3612 KB |
Output is correct |
32 |
Correct |
8 ms |
3540 KB |
Output is correct |
33 |
Correct |
8 ms |
3540 KB |
Output is correct |
34 |
Correct |
9 ms |
3668 KB |
Output is correct |
35 |
Correct |
8 ms |
3540 KB |
Output is correct |
36 |
Correct |
8 ms |
3488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
424 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
1 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
1184 KB |
Output is correct |
11 |
Correct |
2 ms |
1188 KB |
Output is correct |
12 |
Correct |
2 ms |
1236 KB |
Output is correct |
13 |
Correct |
3 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
2 ms |
1108 KB |
Output is correct |
16 |
Correct |
2 ms |
1236 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
1060 KB |
Output is correct |
19 |
Correct |
2 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1204 KB |
Output is correct |
21 |
Correct |
5 ms |
2388 KB |
Output is correct |
22 |
Correct |
5 ms |
2644 KB |
Output is correct |
23 |
Correct |
4 ms |
1876 KB |
Output is correct |
24 |
Correct |
7 ms |
3388 KB |
Output is correct |
25 |
Correct |
7 ms |
3412 KB |
Output is correct |
26 |
Correct |
8 ms |
3600 KB |
Output is correct |
27 |
Correct |
8 ms |
3604 KB |
Output is correct |
28 |
Correct |
8 ms |
3492 KB |
Output is correct |
29 |
Correct |
8 ms |
3492 KB |
Output is correct |
30 |
Correct |
8 ms |
3588 KB |
Output is correct |
31 |
Correct |
8 ms |
3612 KB |
Output is correct |
32 |
Correct |
8 ms |
3540 KB |
Output is correct |
33 |
Correct |
8 ms |
3540 KB |
Output is correct |
34 |
Correct |
9 ms |
3668 KB |
Output is correct |
35 |
Correct |
8 ms |
3540 KB |
Output is correct |
36 |
Correct |
8 ms |
3488 KB |
Output is correct |
37 |
Correct |
18 ms |
6868 KB |
Output is correct |
38 |
Correct |
20 ms |
6944 KB |
Output is correct |
39 |
Correct |
27 ms |
8612 KB |
Output is correct |
40 |
Correct |
28 ms |
9228 KB |
Output is correct |
41 |
Correct |
33 ms |
9372 KB |
Output is correct |
42 |
Correct |
26 ms |
8572 KB |
Output is correct |
43 |
Correct |
30 ms |
8600 KB |
Output is correct |
44 |
Correct |
30 ms |
8732 KB |
Output is correct |
45 |
Correct |
31 ms |
8792 KB |
Output is correct |
46 |
Correct |
29 ms |
9120 KB |
Output is correct |
47 |
Correct |
27 ms |
8580 KB |
Output is correct |
48 |
Correct |
34 ms |
8684 KB |
Output is correct |
49 |
Correct |
30 ms |
8680 KB |
Output is correct |
50 |
Correct |
26 ms |
8580 KB |
Output is correct |
51 |
Correct |
0 ms |
288 KB |
Output is correct |
52 |
Correct |
36 ms |
9496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
424 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
1 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
1184 KB |
Output is correct |
11 |
Correct |
2 ms |
1188 KB |
Output is correct |
12 |
Correct |
2 ms |
1236 KB |
Output is correct |
13 |
Correct |
3 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
2 ms |
1108 KB |
Output is correct |
16 |
Correct |
2 ms |
1236 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
1060 KB |
Output is correct |
19 |
Correct |
2 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1204 KB |
Output is correct |
21 |
Correct |
5 ms |
2388 KB |
Output is correct |
22 |
Correct |
5 ms |
2644 KB |
Output is correct |
23 |
Correct |
4 ms |
1876 KB |
Output is correct |
24 |
Correct |
7 ms |
3388 KB |
Output is correct |
25 |
Correct |
7 ms |
3412 KB |
Output is correct |
26 |
Correct |
8 ms |
3600 KB |
Output is correct |
27 |
Correct |
8 ms |
3604 KB |
Output is correct |
28 |
Correct |
8 ms |
3492 KB |
Output is correct |
29 |
Correct |
8 ms |
3492 KB |
Output is correct |
30 |
Correct |
8 ms |
3588 KB |
Output is correct |
31 |
Correct |
8 ms |
3612 KB |
Output is correct |
32 |
Correct |
8 ms |
3540 KB |
Output is correct |
33 |
Correct |
8 ms |
3540 KB |
Output is correct |
34 |
Correct |
9 ms |
3668 KB |
Output is correct |
35 |
Correct |
8 ms |
3540 KB |
Output is correct |
36 |
Correct |
8 ms |
3488 KB |
Output is correct |
37 |
Correct |
18 ms |
6868 KB |
Output is correct |
38 |
Correct |
20 ms |
6944 KB |
Output is correct |
39 |
Correct |
27 ms |
8612 KB |
Output is correct |
40 |
Correct |
28 ms |
9228 KB |
Output is correct |
41 |
Correct |
33 ms |
9372 KB |
Output is correct |
42 |
Correct |
26 ms |
8572 KB |
Output is correct |
43 |
Correct |
30 ms |
8600 KB |
Output is correct |
44 |
Correct |
30 ms |
8732 KB |
Output is correct |
45 |
Correct |
31 ms |
8792 KB |
Output is correct |
46 |
Correct |
29 ms |
9120 KB |
Output is correct |
47 |
Correct |
27 ms |
8580 KB |
Output is correct |
48 |
Correct |
34 ms |
8684 KB |
Output is correct |
49 |
Correct |
30 ms |
8680 KB |
Output is correct |
50 |
Correct |
26 ms |
8580 KB |
Output is correct |
51 |
Correct |
0 ms |
288 KB |
Output is correct |
52 |
Correct |
36 ms |
9496 KB |
Output is correct |
53 |
Correct |
34 ms |
10260 KB |
Output is correct |
54 |
Correct |
43 ms |
11968 KB |
Output is correct |
55 |
Correct |
65 ms |
12400 KB |
Output is correct |
56 |
Correct |
38 ms |
10572 KB |
Output is correct |
57 |
Correct |
60 ms |
12428 KB |
Output is correct |
58 |
Correct |
45 ms |
12108 KB |
Output is correct |
59 |
Correct |
49 ms |
12140 KB |
Output is correct |
60 |
Correct |
0 ms |
292 KB |
Output is correct |
61 |
Correct |
52 ms |
12164 KB |
Output is correct |
62 |
Correct |
50 ms |
11348 KB |
Output is correct |
63 |
Correct |
52 ms |
11380 KB |
Output is correct |
64 |
Correct |
50 ms |
11192 KB |
Output is correct |
65 |
Correct |
37 ms |
10708 KB |
Output is correct |
66 |
Correct |
35 ms |
10560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
424 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
1 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
1184 KB |
Output is correct |
11 |
Correct |
2 ms |
1188 KB |
Output is correct |
12 |
Correct |
2 ms |
1236 KB |
Output is correct |
13 |
Correct |
3 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
2 ms |
1108 KB |
Output is correct |
16 |
Correct |
2 ms |
1236 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
1060 KB |
Output is correct |
19 |
Correct |
2 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1204 KB |
Output is correct |
21 |
Correct |
5 ms |
2388 KB |
Output is correct |
22 |
Correct |
5 ms |
2644 KB |
Output is correct |
23 |
Correct |
4 ms |
1876 KB |
Output is correct |
24 |
Correct |
7 ms |
3388 KB |
Output is correct |
25 |
Correct |
7 ms |
3412 KB |
Output is correct |
26 |
Correct |
8 ms |
3600 KB |
Output is correct |
27 |
Correct |
8 ms |
3604 KB |
Output is correct |
28 |
Correct |
8 ms |
3492 KB |
Output is correct |
29 |
Correct |
8 ms |
3492 KB |
Output is correct |
30 |
Correct |
8 ms |
3588 KB |
Output is correct |
31 |
Correct |
8 ms |
3612 KB |
Output is correct |
32 |
Correct |
8 ms |
3540 KB |
Output is correct |
33 |
Correct |
8 ms |
3540 KB |
Output is correct |
34 |
Correct |
9 ms |
3668 KB |
Output is correct |
35 |
Correct |
8 ms |
3540 KB |
Output is correct |
36 |
Correct |
8 ms |
3488 KB |
Output is correct |
37 |
Correct |
18 ms |
6868 KB |
Output is correct |
38 |
Correct |
20 ms |
6944 KB |
Output is correct |
39 |
Correct |
27 ms |
8612 KB |
Output is correct |
40 |
Correct |
28 ms |
9228 KB |
Output is correct |
41 |
Correct |
33 ms |
9372 KB |
Output is correct |
42 |
Correct |
26 ms |
8572 KB |
Output is correct |
43 |
Correct |
30 ms |
8600 KB |
Output is correct |
44 |
Correct |
30 ms |
8732 KB |
Output is correct |
45 |
Correct |
31 ms |
8792 KB |
Output is correct |
46 |
Correct |
29 ms |
9120 KB |
Output is correct |
47 |
Correct |
27 ms |
8580 KB |
Output is correct |
48 |
Correct |
34 ms |
8684 KB |
Output is correct |
49 |
Correct |
30 ms |
8680 KB |
Output is correct |
50 |
Correct |
26 ms |
8580 KB |
Output is correct |
51 |
Correct |
0 ms |
288 KB |
Output is correct |
52 |
Correct |
36 ms |
9496 KB |
Output is correct |
53 |
Correct |
34 ms |
10260 KB |
Output is correct |
54 |
Correct |
43 ms |
11968 KB |
Output is correct |
55 |
Correct |
65 ms |
12400 KB |
Output is correct |
56 |
Correct |
38 ms |
10572 KB |
Output is correct |
57 |
Correct |
60 ms |
12428 KB |
Output is correct |
58 |
Correct |
45 ms |
12108 KB |
Output is correct |
59 |
Correct |
49 ms |
12140 KB |
Output is correct |
60 |
Correct |
0 ms |
292 KB |
Output is correct |
61 |
Correct |
52 ms |
12164 KB |
Output is correct |
62 |
Correct |
50 ms |
11348 KB |
Output is correct |
63 |
Correct |
52 ms |
11380 KB |
Output is correct |
64 |
Correct |
50 ms |
11192 KB |
Output is correct |
65 |
Correct |
37 ms |
10708 KB |
Output is correct |
66 |
Correct |
35 ms |
10560 KB |
Output is correct |
67 |
Correct |
63 ms |
13776 KB |
Output is correct |
68 |
Correct |
10 ms |
16504 KB |
Output is correct |
69 |
Correct |
123 ms |
18068 KB |
Output is correct |
70 |
Correct |
91 ms |
17468 KB |
Output is correct |
71 |
Correct |
90 ms |
17356 KB |
Output is correct |
72 |
Correct |
87 ms |
17068 KB |
Output is correct |
73 |
Correct |
88 ms |
17064 KB |
Output is correct |
74 |
Correct |
131 ms |
18164 KB |
Output is correct |
75 |
Correct |
111 ms |
17740 KB |
Output is correct |
76 |
Correct |
134 ms |
18172 KB |
Output is correct |
77 |
Correct |
135 ms |
18144 KB |
Output is correct |