답안 #36836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36836 2017-12-16T04:35:10 Z szawinis Bootfall (IZhO17_bootfall) C++14
100 / 100
836 ms 8728 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 501, M = 3e5+1;

int n, sum, a[N], cnt[M];
long long dp[M], tmp[M];
int main() {
	scanf("%d", &n);
	dp[0] = 1;
	for(int i = 0; i < n; i++) {
		scanf("%d", a+i);
		sum += a[i];
		for(int j = M-1; j >= a[i]; j--) dp[j] += dp[j - a[i]];
	}
	if(sum % 2 || !dp[sum >> 1]) printf("0"), exit(0);
	for(int i = 0; i < n; i++) {
		copy(dp, dp+M, tmp);
		for(int j = a[i]; j < M; j++) tmp[j] -= tmp[j - a[i]]; // pay attention to order, only want to remove ones invalidated, not all combinations
		for(int x = 0; x < M; x++) {
			int val = sum - a[i] + x; // new sum of entire sequence including n+1
			cnt[x] += val % 2 == 0 && tmp[val >> 1];
		}
	}
	vector<int> ans;
	for(int x = 0; x < M; x++) if(cnt[x] == n) ans.push_back(x);
	printf("%d\n", ans.size());
	for(int x: ans) printf("%d ", x);
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:26:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", ans.size());
                           ^
bootfall.cpp:8:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
bootfall.cpp:11:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a+i);
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7876 KB Output is correct
2 Correct 9 ms 7876 KB Output is correct
3 Correct 0 ms 7876 KB Output is correct
4 Correct 6 ms 7876 KB Output is correct
5 Correct 26 ms 7876 KB Output is correct
6 Correct 13 ms 7876 KB Output is correct
7 Correct 9 ms 7876 KB Output is correct
8 Correct 16 ms 7876 KB Output is correct
9 Correct 19 ms 7876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7876 KB Output is correct
2 Correct 9 ms 7876 KB Output is correct
3 Correct 0 ms 7876 KB Output is correct
4 Correct 6 ms 7876 KB Output is correct
5 Correct 26 ms 7876 KB Output is correct
6 Correct 13 ms 7876 KB Output is correct
7 Correct 9 ms 7876 KB Output is correct
8 Correct 16 ms 7876 KB Output is correct
9 Correct 19 ms 7876 KB Output is correct
10 Correct 39 ms 7876 KB Output is correct
11 Correct 49 ms 7876 KB Output is correct
12 Correct 43 ms 7876 KB Output is correct
13 Correct 43 ms 7876 KB Output is correct
14 Correct 39 ms 7876 KB Output is correct
15 Correct 39 ms 7876 KB Output is correct
16 Correct 46 ms 7876 KB Output is correct
17 Correct 26 ms 7876 KB Output is correct
18 Correct 36 ms 7876 KB Output is correct
19 Correct 36 ms 7876 KB Output is correct
20 Correct 43 ms 7876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7876 KB Output is correct
2 Correct 9 ms 7876 KB Output is correct
3 Correct 0 ms 7876 KB Output is correct
4 Correct 6 ms 7876 KB Output is correct
5 Correct 26 ms 7876 KB Output is correct
6 Correct 13 ms 7876 KB Output is correct
7 Correct 9 ms 7876 KB Output is correct
8 Correct 16 ms 7876 KB Output is correct
9 Correct 19 ms 7876 KB Output is correct
10 Correct 39 ms 7876 KB Output is correct
11 Correct 49 ms 7876 KB Output is correct
12 Correct 43 ms 7876 KB Output is correct
13 Correct 43 ms 7876 KB Output is correct
14 Correct 39 ms 7876 KB Output is correct
15 Correct 39 ms 7876 KB Output is correct
16 Correct 46 ms 7876 KB Output is correct
17 Correct 26 ms 7876 KB Output is correct
18 Correct 36 ms 7876 KB Output is correct
19 Correct 36 ms 7876 KB Output is correct
20 Correct 43 ms 7876 KB Output is correct
21 Correct 93 ms 7876 KB Output is correct
22 Correct 106 ms 7876 KB Output is correct
23 Correct 76 ms 7876 KB Output is correct
24 Correct 143 ms 7876 KB Output is correct
25 Correct 133 ms 7876 KB Output is correct
26 Correct 143 ms 7876 KB Output is correct
27 Correct 149 ms 7876 KB Output is correct
28 Correct 146 ms 7876 KB Output is correct
29 Correct 143 ms 7876 KB Output is correct
30 Correct 146 ms 7876 KB Output is correct
31 Correct 143 ms 7876 KB Output is correct
32 Correct 156 ms 7876 KB Output is correct
33 Correct 159 ms 7876 KB Output is correct
34 Correct 183 ms 7876 KB Output is correct
35 Correct 149 ms 7876 KB Output is correct
36 Correct 163 ms 7876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7876 KB Output is correct
2 Correct 9 ms 7876 KB Output is correct
3 Correct 0 ms 7876 KB Output is correct
4 Correct 6 ms 7876 KB Output is correct
5 Correct 26 ms 7876 KB Output is correct
6 Correct 13 ms 7876 KB Output is correct
7 Correct 9 ms 7876 KB Output is correct
8 Correct 16 ms 7876 KB Output is correct
9 Correct 19 ms 7876 KB Output is correct
10 Correct 39 ms 7876 KB Output is correct
11 Correct 49 ms 7876 KB Output is correct
12 Correct 43 ms 7876 KB Output is correct
13 Correct 43 ms 7876 KB Output is correct
14 Correct 39 ms 7876 KB Output is correct
15 Correct 39 ms 7876 KB Output is correct
16 Correct 46 ms 7876 KB Output is correct
17 Correct 26 ms 7876 KB Output is correct
18 Correct 36 ms 7876 KB Output is correct
19 Correct 36 ms 7876 KB Output is correct
20 Correct 43 ms 7876 KB Output is correct
21 Correct 93 ms 7876 KB Output is correct
22 Correct 106 ms 7876 KB Output is correct
23 Correct 76 ms 7876 KB Output is correct
24 Correct 143 ms 7876 KB Output is correct
25 Correct 133 ms 7876 KB Output is correct
26 Correct 143 ms 7876 KB Output is correct
27 Correct 149 ms 7876 KB Output is correct
28 Correct 146 ms 7876 KB Output is correct
29 Correct 143 ms 7876 KB Output is correct
30 Correct 146 ms 7876 KB Output is correct
31 Correct 143 ms 7876 KB Output is correct
32 Correct 156 ms 7876 KB Output is correct
33 Correct 159 ms 7876 KB Output is correct
34 Correct 183 ms 7876 KB Output is correct
35 Correct 149 ms 7876 KB Output is correct
36 Correct 163 ms 7876 KB Output is correct
37 Correct 299 ms 8016 KB Output is correct
38 Correct 309 ms 8016 KB Output is correct
39 Correct 386 ms 7876 KB Output is correct
40 Correct 456 ms 8016 KB Output is correct
41 Correct 423 ms 7876 KB Output is correct
42 Correct 403 ms 8016 KB Output is correct
43 Correct 416 ms 8148 KB Output is correct
44 Correct 393 ms 8148 KB Output is correct
45 Correct 406 ms 8148 KB Output is correct
46 Correct 409 ms 7876 KB Output is correct
47 Correct 389 ms 8016 KB Output is correct
48 Correct 396 ms 8148 KB Output is correct
49 Correct 409 ms 8016 KB Output is correct
50 Correct 379 ms 8016 KB Output is correct
51 Correct 79 ms 7876 KB Output is correct
52 Correct 406 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7876 KB Output is correct
2 Correct 9 ms 7876 KB Output is correct
3 Correct 0 ms 7876 KB Output is correct
4 Correct 6 ms 7876 KB Output is correct
5 Correct 26 ms 7876 KB Output is correct
6 Correct 13 ms 7876 KB Output is correct
7 Correct 9 ms 7876 KB Output is correct
8 Correct 16 ms 7876 KB Output is correct
9 Correct 19 ms 7876 KB Output is correct
10 Correct 39 ms 7876 KB Output is correct
11 Correct 49 ms 7876 KB Output is correct
12 Correct 43 ms 7876 KB Output is correct
13 Correct 43 ms 7876 KB Output is correct
14 Correct 39 ms 7876 KB Output is correct
15 Correct 39 ms 7876 KB Output is correct
16 Correct 46 ms 7876 KB Output is correct
17 Correct 26 ms 7876 KB Output is correct
18 Correct 36 ms 7876 KB Output is correct
19 Correct 36 ms 7876 KB Output is correct
20 Correct 43 ms 7876 KB Output is correct
21 Correct 93 ms 7876 KB Output is correct
22 Correct 106 ms 7876 KB Output is correct
23 Correct 76 ms 7876 KB Output is correct
24 Correct 143 ms 7876 KB Output is correct
25 Correct 133 ms 7876 KB Output is correct
26 Correct 143 ms 7876 KB Output is correct
27 Correct 149 ms 7876 KB Output is correct
28 Correct 146 ms 7876 KB Output is correct
29 Correct 143 ms 7876 KB Output is correct
30 Correct 146 ms 7876 KB Output is correct
31 Correct 143 ms 7876 KB Output is correct
32 Correct 156 ms 7876 KB Output is correct
33 Correct 159 ms 7876 KB Output is correct
34 Correct 183 ms 7876 KB Output is correct
35 Correct 149 ms 7876 KB Output is correct
36 Correct 163 ms 7876 KB Output is correct
37 Correct 299 ms 8016 KB Output is correct
38 Correct 309 ms 8016 KB Output is correct
39 Correct 386 ms 7876 KB Output is correct
40 Correct 456 ms 8016 KB Output is correct
41 Correct 423 ms 7876 KB Output is correct
42 Correct 403 ms 8016 KB Output is correct
43 Correct 416 ms 8148 KB Output is correct
44 Correct 393 ms 8148 KB Output is correct
45 Correct 406 ms 8148 KB Output is correct
46 Correct 409 ms 7876 KB Output is correct
47 Correct 389 ms 8016 KB Output is correct
48 Correct 396 ms 8148 KB Output is correct
49 Correct 409 ms 8016 KB Output is correct
50 Correct 379 ms 8016 KB Output is correct
51 Correct 79 ms 7876 KB Output is correct
52 Correct 406 ms 8148 KB Output is correct
53 Correct 553 ms 8148 KB Output is correct
54 Correct 579 ms 8148 KB Output is correct
55 Correct 556 ms 8344 KB Output is correct
56 Correct 476 ms 8148 KB Output is correct
57 Correct 539 ms 8344 KB Output is correct
58 Correct 546 ms 8148 KB Output is correct
59 Correct 566 ms 8344 KB Output is correct
60 Correct 103 ms 7876 KB Output is correct
61 Correct 553 ms 8344 KB Output is correct
62 Correct 526 ms 8344 KB Output is correct
63 Correct 503 ms 8344 KB Output is correct
64 Correct 496 ms 8344 KB Output is correct
65 Correct 503 ms 7876 KB Output is correct
66 Correct 479 ms 8016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7876 KB Output is correct
2 Correct 9 ms 7876 KB Output is correct
3 Correct 0 ms 7876 KB Output is correct
4 Correct 6 ms 7876 KB Output is correct
5 Correct 26 ms 7876 KB Output is correct
6 Correct 13 ms 7876 KB Output is correct
7 Correct 9 ms 7876 KB Output is correct
8 Correct 16 ms 7876 KB Output is correct
9 Correct 19 ms 7876 KB Output is correct
10 Correct 39 ms 7876 KB Output is correct
11 Correct 49 ms 7876 KB Output is correct
12 Correct 43 ms 7876 KB Output is correct
13 Correct 43 ms 7876 KB Output is correct
14 Correct 39 ms 7876 KB Output is correct
15 Correct 39 ms 7876 KB Output is correct
16 Correct 46 ms 7876 KB Output is correct
17 Correct 26 ms 7876 KB Output is correct
18 Correct 36 ms 7876 KB Output is correct
19 Correct 36 ms 7876 KB Output is correct
20 Correct 43 ms 7876 KB Output is correct
21 Correct 93 ms 7876 KB Output is correct
22 Correct 106 ms 7876 KB Output is correct
23 Correct 76 ms 7876 KB Output is correct
24 Correct 143 ms 7876 KB Output is correct
25 Correct 133 ms 7876 KB Output is correct
26 Correct 143 ms 7876 KB Output is correct
27 Correct 149 ms 7876 KB Output is correct
28 Correct 146 ms 7876 KB Output is correct
29 Correct 143 ms 7876 KB Output is correct
30 Correct 146 ms 7876 KB Output is correct
31 Correct 143 ms 7876 KB Output is correct
32 Correct 156 ms 7876 KB Output is correct
33 Correct 159 ms 7876 KB Output is correct
34 Correct 183 ms 7876 KB Output is correct
35 Correct 149 ms 7876 KB Output is correct
36 Correct 163 ms 7876 KB Output is correct
37 Correct 299 ms 8016 KB Output is correct
38 Correct 309 ms 8016 KB Output is correct
39 Correct 386 ms 7876 KB Output is correct
40 Correct 456 ms 8016 KB Output is correct
41 Correct 423 ms 7876 KB Output is correct
42 Correct 403 ms 8016 KB Output is correct
43 Correct 416 ms 8148 KB Output is correct
44 Correct 393 ms 8148 KB Output is correct
45 Correct 406 ms 8148 KB Output is correct
46 Correct 409 ms 7876 KB Output is correct
47 Correct 389 ms 8016 KB Output is correct
48 Correct 396 ms 8148 KB Output is correct
49 Correct 409 ms 8016 KB Output is correct
50 Correct 379 ms 8016 KB Output is correct
51 Correct 79 ms 7876 KB Output is correct
52 Correct 406 ms 8148 KB Output is correct
53 Correct 553 ms 8148 KB Output is correct
54 Correct 579 ms 8148 KB Output is correct
55 Correct 556 ms 8344 KB Output is correct
56 Correct 476 ms 8148 KB Output is correct
57 Correct 539 ms 8344 KB Output is correct
58 Correct 546 ms 8148 KB Output is correct
59 Correct 566 ms 8344 KB Output is correct
60 Correct 103 ms 7876 KB Output is correct
61 Correct 553 ms 8344 KB Output is correct
62 Correct 526 ms 8344 KB Output is correct
63 Correct 503 ms 8344 KB Output is correct
64 Correct 496 ms 8344 KB Output is correct
65 Correct 503 ms 7876 KB Output is correct
66 Correct 479 ms 8016 KB Output is correct
67 Correct 629 ms 8344 KB Output is correct
68 Correct 146 ms 7876 KB Output is correct
69 Correct 829 ms 8728 KB Output is correct
70 Correct 809 ms 8344 KB Output is correct
71 Correct 836 ms 8344 KB Output is correct
72 Correct 789 ms 7876 KB Output is correct
73 Correct 769 ms 7876 KB Output is correct
74 Correct 783 ms 8728 KB Output is correct
75 Correct 789 ms 8728 KB Output is correct
76 Correct 806 ms 8728 KB Output is correct
77 Correct 783 ms 8728 KB Output is correct