Submission #173518

# Submission time Handle Problem Language Result Execution time Memory
173518 2020-01-04T11:28:13 Z AllMight Bootfall (IZhO17_bootfall) C++14
100 / 100
468 ms 4080 KB
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 502;

int n;
int a[N];

int knp[N * N];
int cnt[N * N];
vector <int> v;

void check(int ind, int sum)
{
	for (int i = a[ind]; i <= sum; i++)
		knp[i] -= knp[i - a[ind]];

	sum -= a[ind];
	for (int i = 0; 2 * i < sum; i++) {
		if (!knp[i])	continue;
		int ans = sum - 2 * i;
		cnt[ans]++;
		if (ind == 0)
			v.push_back(ans);
	}

	for (int i = sum; i >= 0; i--)
		knp[i + a[ind]] += knp[i];
}

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n;

	int mx = 0;
	knp[0] = 1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for (int j = mx; j >= 0; j--) {
			if (knp[j]) {
				knp[j + a[i]] += knp[j];
				mx = max(mx, j + a[i]);
			}
		}
	}
	int sum = mx;
	if (sum % 2 || !knp[sum / 2]) {
		cout << "0\n";
		return 0;
	}

	for (int i = 0; i < n; i++)
		check(i, sum);

	vector <int> ans;
	for (int i = 0; i < v.size(); i++)
		if (cnt[v[i]] == n)
			ans.push_back(v[i]);

	sort(ans.begin(), ans.end());
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] << ' ';
	cout << endl;

	return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:61:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v.size(); i++)
                  ~~^~~~~~~~~~
bootfall.cpp:67:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); i++)
                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 5 ms 504 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 4 ms 376 KB Output is correct
34 Correct 4 ms 404 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 5 ms 504 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 4 ms 376 KB Output is correct
34 Correct 4 ms 404 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 18 ms 632 KB Output is correct
38 Correct 19 ms 760 KB Output is correct
39 Correct 32 ms 760 KB Output is correct
40 Correct 38 ms 888 KB Output is correct
41 Correct 42 ms 888 KB Output is correct
42 Correct 33 ms 888 KB Output is correct
43 Correct 56 ms 1272 KB Output is correct
44 Correct 58 ms 1272 KB Output is correct
45 Correct 59 ms 1272 KB Output is correct
46 Correct 26 ms 632 KB Output is correct
47 Correct 36 ms 888 KB Output is correct
48 Correct 54 ms 1272 KB Output is correct
49 Correct 44 ms 1016 KB Output is correct
50 Correct 37 ms 888 KB Output is correct
51 Correct 17 ms 424 KB Output is correct
52 Correct 73 ms 1448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 5 ms 504 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 4 ms 376 KB Output is correct
34 Correct 4 ms 404 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 18 ms 632 KB Output is correct
38 Correct 19 ms 760 KB Output is correct
39 Correct 32 ms 760 KB Output is correct
40 Correct 38 ms 888 KB Output is correct
41 Correct 42 ms 888 KB Output is correct
42 Correct 33 ms 888 KB Output is correct
43 Correct 56 ms 1272 KB Output is correct
44 Correct 58 ms 1272 KB Output is correct
45 Correct 59 ms 1272 KB Output is correct
46 Correct 26 ms 632 KB Output is correct
47 Correct 36 ms 888 KB Output is correct
48 Correct 54 ms 1272 KB Output is correct
49 Correct 44 ms 1016 KB Output is correct
50 Correct 37 ms 888 KB Output is correct
51 Correct 17 ms 424 KB Output is correct
52 Correct 73 ms 1448 KB Output is correct
53 Correct 59 ms 1104 KB Output is correct
54 Correct 82 ms 1272 KB Output is correct
55 Correct 151 ms 2036 KB Output is correct
56 Correct 73 ms 1340 KB Output is correct
57 Correct 164 ms 2296 KB Output is correct
58 Correct 91 ms 1400 KB Output is correct
59 Correct 114 ms 1752 KB Output is correct
60 Correct 42 ms 632 KB Output is correct
61 Correct 126 ms 1792 KB Output is correct
62 Correct 128 ms 1908 KB Output is correct
63 Correct 135 ms 1908 KB Output is correct
64 Correct 131 ms 2036 KB Output is correct
65 Correct 37 ms 760 KB Output is correct
66 Correct 38 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 5 ms 504 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 4 ms 376 KB Output is correct
34 Correct 4 ms 404 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 18 ms 632 KB Output is correct
38 Correct 19 ms 760 KB Output is correct
39 Correct 32 ms 760 KB Output is correct
40 Correct 38 ms 888 KB Output is correct
41 Correct 42 ms 888 KB Output is correct
42 Correct 33 ms 888 KB Output is correct
43 Correct 56 ms 1272 KB Output is correct
44 Correct 58 ms 1272 KB Output is correct
45 Correct 59 ms 1272 KB Output is correct
46 Correct 26 ms 632 KB Output is correct
47 Correct 36 ms 888 KB Output is correct
48 Correct 54 ms 1272 KB Output is correct
49 Correct 44 ms 1016 KB Output is correct
50 Correct 37 ms 888 KB Output is correct
51 Correct 17 ms 424 KB Output is correct
52 Correct 73 ms 1448 KB Output is correct
53 Correct 59 ms 1104 KB Output is correct
54 Correct 82 ms 1272 KB Output is correct
55 Correct 151 ms 2036 KB Output is correct
56 Correct 73 ms 1340 KB Output is correct
57 Correct 164 ms 2296 KB Output is correct
58 Correct 91 ms 1400 KB Output is correct
59 Correct 114 ms 1752 KB Output is correct
60 Correct 42 ms 632 KB Output is correct
61 Correct 126 ms 1792 KB Output is correct
62 Correct 128 ms 1908 KB Output is correct
63 Correct 135 ms 1908 KB Output is correct
64 Correct 131 ms 2036 KB Output is correct
65 Correct 37 ms 760 KB Output is correct
66 Correct 38 ms 888 KB Output is correct
67 Correct 113 ms 1648 KB Output is correct
68 Correct 66 ms 760 KB Output is correct
69 Correct 421 ms 3676 KB Output is correct
70 Correct 268 ms 2548 KB Output is correct
71 Correct 260 ms 2292 KB Output is correct
72 Correct 255 ms 1704 KB Output is correct
73 Correct 252 ms 1652 KB Output is correct
74 Correct 450 ms 3828 KB Output is correct
75 Correct 355 ms 3144 KB Output is correct
76 Correct 453 ms 4028 KB Output is correct
77 Correct 468 ms 4080 KB Output is correct