답안 #229888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229888 2020-05-07T03:43:47 Z pedroslrey Bootfall (IZhO17_bootfall) C++14
100 / 100
935 ms 3568 KB
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using pii = pair<int, int>;
using lli = long long int;

#define debug(args...) fprintf(stderr, args)
#define pb push_back
#define fi first
#define se second
#define all(xs) xs.begin(), xs.end()

const int INF = 1e9;

int dp[510*510];
int xs[510];
int marc[510*510];

inline void add(int i, int s) {
	for (int k = s; k >= 0; --k) {
		lli tmp = 1LL*dp[k + xs[i]] + dp[k];
		dp[k + xs[i]] = tmp%INF;
	}
}

inline void sub(int i, int s) {
	for (int k = 0; k <= s; ++k) {
		lli tmp = 1LL*dp[k + xs[i]] - dp[k];
		dp[k + xs[i]] = tmp%INF;
	}
}

void init_dp(int n, int s) {
	dp[0] = 1;
	
	for (int i = 1; i <= n; ++i)
		add(i, s);
}

void solve(int n) {
	int s = 0;
	for (int i = 1; i <= n; ++i) 
		s += xs[i];

	init_dp(n, s);
	if (dp[s/2] == 0 || s%2 == 1) {
		printf("0\n");
		return;
	}

	for (int i = 1; i <= n; ++i) {
		sub(i, s);
		for (int k = 1; k <= s; ++k) {
			if ((s - xs[i] + k)%2 == 1) marc[k] = 0;
			if (s - xs[i] - k < 0) continue;
			else if (dp[(s - xs[i] - k)/2]) ++marc[k];
		} 
		add(i, s);
	}

	vector<int> ans;
	for (int k = 1; k <= s; ++k) 
		if (marc[k] == n) ans.pb(k);

	printf("%d\n", (int) ans.size());
	for (int a: ans) 
		printf("%d ", a);
	printf("\n");
}

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; ++i)
		scanf("%d", &xs[i]);

	solve(n);
}

Compilation message

bootfall.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
bootfall.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
bootfall.cpp: In function 'int main()':
bootfall.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
bootfall.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &xs[i]);
   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 9 ms 384 KB Output is correct
25 Correct 11 ms 384 KB Output is correct
26 Correct 12 ms 384 KB Output is correct
27 Correct 12 ms 512 KB Output is correct
28 Correct 15 ms 384 KB Output is correct
29 Correct 12 ms 384 KB Output is correct
30 Correct 8 ms 384 KB Output is correct
31 Correct 11 ms 384 KB Output is correct
32 Correct 8 ms 384 KB Output is correct
33 Correct 12 ms 384 KB Output is correct
34 Correct 12 ms 384 KB Output is correct
35 Correct 12 ms 384 KB Output is correct
36 Correct 9 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 9 ms 384 KB Output is correct
25 Correct 11 ms 384 KB Output is correct
26 Correct 12 ms 384 KB Output is correct
27 Correct 12 ms 512 KB Output is correct
28 Correct 15 ms 384 KB Output is correct
29 Correct 12 ms 384 KB Output is correct
30 Correct 8 ms 384 KB Output is correct
31 Correct 11 ms 384 KB Output is correct
32 Correct 8 ms 384 KB Output is correct
33 Correct 12 ms 384 KB Output is correct
34 Correct 12 ms 384 KB Output is correct
35 Correct 12 ms 384 KB Output is correct
36 Correct 9 ms 384 KB Output is correct
37 Correct 34 ms 632 KB Output is correct
38 Correct 35 ms 576 KB Output is correct
39 Correct 117 ms 760 KB Output is correct
40 Correct 71 ms 756 KB Output is correct
41 Correct 152 ms 892 KB Output is correct
42 Correct 63 ms 768 KB Output is correct
43 Correct 108 ms 1144 KB Output is correct
44 Correct 110 ms 1144 KB Output is correct
45 Correct 113 ms 1200 KB Output is correct
46 Correct 69 ms 512 KB Output is correct
47 Correct 67 ms 760 KB Output is correct
48 Correct 121 ms 1144 KB Output is correct
49 Correct 123 ms 888 KB Output is correct
50 Correct 65 ms 760 KB Output is correct
51 Correct 19 ms 512 KB Output is correct
52 Correct 147 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 9 ms 384 KB Output is correct
25 Correct 11 ms 384 KB Output is correct
26 Correct 12 ms 384 KB Output is correct
27 Correct 12 ms 512 KB Output is correct
28 Correct 15 ms 384 KB Output is correct
29 Correct 12 ms 384 KB Output is correct
30 Correct 8 ms 384 KB Output is correct
31 Correct 11 ms 384 KB Output is correct
32 Correct 8 ms 384 KB Output is correct
33 Correct 12 ms 384 KB Output is correct
34 Correct 12 ms 384 KB Output is correct
35 Correct 12 ms 384 KB Output is correct
36 Correct 9 ms 384 KB Output is correct
37 Correct 34 ms 632 KB Output is correct
38 Correct 35 ms 576 KB Output is correct
39 Correct 117 ms 760 KB Output is correct
40 Correct 71 ms 756 KB Output is correct
41 Correct 152 ms 892 KB Output is correct
42 Correct 63 ms 768 KB Output is correct
43 Correct 108 ms 1144 KB Output is correct
44 Correct 110 ms 1144 KB Output is correct
45 Correct 113 ms 1200 KB Output is correct
46 Correct 69 ms 512 KB Output is correct
47 Correct 67 ms 760 KB Output is correct
48 Correct 121 ms 1144 KB Output is correct
49 Correct 123 ms 888 KB Output is correct
50 Correct 65 ms 760 KB Output is correct
51 Correct 19 ms 512 KB Output is correct
52 Correct 147 ms 1272 KB Output is correct
53 Correct 106 ms 1016 KB Output is correct
54 Correct 151 ms 1144 KB Output is correct
55 Correct 298 ms 1780 KB Output is correct
56 Correct 135 ms 1144 KB Output is correct
57 Correct 309 ms 1908 KB Output is correct
58 Correct 165 ms 1272 KB Output is correct
59 Correct 204 ms 1652 KB Output is correct
60 Correct 44 ms 512 KB Output is correct
61 Correct 227 ms 1652 KB Output is correct
62 Correct 236 ms 1652 KB Output is correct
63 Correct 250 ms 1780 KB Output is correct
64 Correct 244 ms 1780 KB Output is correct
65 Correct 123 ms 760 KB Output is correct
66 Correct 134 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 9 ms 384 KB Output is correct
25 Correct 11 ms 384 KB Output is correct
26 Correct 12 ms 384 KB Output is correct
27 Correct 12 ms 512 KB Output is correct
28 Correct 15 ms 384 KB Output is correct
29 Correct 12 ms 384 KB Output is correct
30 Correct 8 ms 384 KB Output is correct
31 Correct 11 ms 384 KB Output is correct
32 Correct 8 ms 384 KB Output is correct
33 Correct 12 ms 384 KB Output is correct
34 Correct 12 ms 384 KB Output is correct
35 Correct 12 ms 384 KB Output is correct
36 Correct 9 ms 384 KB Output is correct
37 Correct 34 ms 632 KB Output is correct
38 Correct 35 ms 576 KB Output is correct
39 Correct 117 ms 760 KB Output is correct
40 Correct 71 ms 756 KB Output is correct
41 Correct 152 ms 892 KB Output is correct
42 Correct 63 ms 768 KB Output is correct
43 Correct 108 ms 1144 KB Output is correct
44 Correct 110 ms 1144 KB Output is correct
45 Correct 113 ms 1200 KB Output is correct
46 Correct 69 ms 512 KB Output is correct
47 Correct 67 ms 760 KB Output is correct
48 Correct 121 ms 1144 KB Output is correct
49 Correct 123 ms 888 KB Output is correct
50 Correct 65 ms 760 KB Output is correct
51 Correct 19 ms 512 KB Output is correct
52 Correct 147 ms 1272 KB Output is correct
53 Correct 106 ms 1016 KB Output is correct
54 Correct 151 ms 1144 KB Output is correct
55 Correct 298 ms 1780 KB Output is correct
56 Correct 135 ms 1144 KB Output is correct
57 Correct 309 ms 1908 KB Output is correct
58 Correct 165 ms 1272 KB Output is correct
59 Correct 204 ms 1652 KB Output is correct
60 Correct 44 ms 512 KB Output is correct
61 Correct 227 ms 1652 KB Output is correct
62 Correct 236 ms 1652 KB Output is correct
63 Correct 250 ms 1780 KB Output is correct
64 Correct 244 ms 1780 KB Output is correct
65 Correct 123 ms 760 KB Output is correct
66 Correct 134 ms 760 KB Output is correct
67 Correct 247 ms 1396 KB Output is correct
68 Correct 115 ms 768 KB Output is correct
69 Correct 794 ms 3108 KB Output is correct
70 Correct 474 ms 2164 KB Output is correct
71 Correct 458 ms 2168 KB Output is correct
72 Correct 460 ms 1272 KB Output is correct
73 Correct 459 ms 1400 KB Output is correct
74 Correct 831 ms 3288 KB Output is correct
75 Correct 646 ms 2672 KB Output is correct
76 Correct 921 ms 3440 KB Output is correct
77 Correct 935 ms 3568 KB Output is correct