Submission #51309

# Submission time Handle Problem Language Result Execution time Memory
51309 2018-06-17T12:42:33 Z Nicksechko Bootfall (IZhO17_bootfall) C++14
100 / 100
895 ms 3252 KB
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

const int MX = 250005;
const int MOD = 1e9 + 7;
int n;
int a[502];
int dp[MX];
int fl[MX];
int sum = 0;

void add(int x) {
	for (int i = sum; i >= 0; --i)
		dp[i + x] = (dp[i + x] + dp[i]) % MOD;
	sum += x;
}

void del(int x) {
	sum -= x;
	for (int i = 0; i <= sum; ++i) {
		dp[i + x] = (dp[i + x] - dp[i] + MOD) % MOD;
	}
}

int main() {
//	freopen("bootfall.in", "r", stdin);
//	freopen("bootfall.out", "w", stdout);
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 1; i < MX; ++i)
		fl[i] = 1;
	dp[0] = 1;
	for (int i = 0; i < n; ++i)
		add(a[i]);
	if (sum % 2 == 1 || !dp[sum / 2]) {
		cout << 0 << "\n";
		return 0;
	}
	for (int i = 0; i < n; ++i) {
		del(a[i]);
		for (int j = 1; j < MX; ++j) {
			if ((sum + j) % 2 == 1 || !dp[(sum + j) / 2])
				fl[j] = 0;
		}
		add(a[i]);
	}
	int cnt = 0;
	for (int i = 0; i < MX; ++i)
		cnt += fl[i];
	cout << cnt << "\n";
	for (int i = 0; i < MX; ++i)
		if (fl[i])
			cout << i << " ";
	cout << "\n";
	return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 5 ms 1380 KB Output is correct
3 Correct 3 ms 1380 KB Output is correct
4 Correct 5 ms 1380 KB Output is correct
5 Correct 8 ms 1380 KB Output is correct
6 Correct 6 ms 1432 KB Output is correct
7 Correct 5 ms 1432 KB Output is correct
8 Correct 8 ms 1512 KB Output is correct
9 Correct 8 ms 1552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 5 ms 1380 KB Output is correct
3 Correct 3 ms 1380 KB Output is correct
4 Correct 5 ms 1380 KB Output is correct
5 Correct 8 ms 1380 KB Output is correct
6 Correct 6 ms 1432 KB Output is correct
7 Correct 5 ms 1432 KB Output is correct
8 Correct 8 ms 1512 KB Output is correct
9 Correct 8 ms 1552 KB Output is correct
10 Correct 15 ms 1552 KB Output is correct
11 Correct 16 ms 1552 KB Output is correct
12 Correct 17 ms 1816 KB Output is correct
13 Correct 14 ms 1816 KB Output is correct
14 Correct 15 ms 1816 KB Output is correct
15 Correct 14 ms 1816 KB Output is correct
16 Correct 17 ms 1816 KB Output is correct
17 Correct 10 ms 1816 KB Output is correct
18 Correct 14 ms 1816 KB Output is correct
19 Correct 14 ms 1816 KB Output is correct
20 Correct 15 ms 1816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 5 ms 1380 KB Output is correct
3 Correct 3 ms 1380 KB Output is correct
4 Correct 5 ms 1380 KB Output is correct
5 Correct 8 ms 1380 KB Output is correct
6 Correct 6 ms 1432 KB Output is correct
7 Correct 5 ms 1432 KB Output is correct
8 Correct 8 ms 1512 KB Output is correct
9 Correct 8 ms 1552 KB Output is correct
10 Correct 15 ms 1552 KB Output is correct
11 Correct 16 ms 1552 KB Output is correct
12 Correct 17 ms 1816 KB Output is correct
13 Correct 14 ms 1816 KB Output is correct
14 Correct 15 ms 1816 KB Output is correct
15 Correct 14 ms 1816 KB Output is correct
16 Correct 17 ms 1816 KB Output is correct
17 Correct 10 ms 1816 KB Output is correct
18 Correct 14 ms 1816 KB Output is correct
19 Correct 14 ms 1816 KB Output is correct
20 Correct 15 ms 1816 KB Output is correct
21 Correct 32 ms 1816 KB Output is correct
22 Correct 36 ms 1816 KB Output is correct
23 Correct 31 ms 1816 KB Output is correct
24 Correct 46 ms 1816 KB Output is correct
25 Correct 45 ms 1816 KB Output is correct
26 Correct 51 ms 1816 KB Output is correct
27 Correct 50 ms 1816 KB Output is correct
28 Correct 57 ms 1816 KB Output is correct
29 Correct 50 ms 1816 KB Output is correct
30 Correct 50 ms 1816 KB Output is correct
31 Correct 51 ms 1816 KB Output is correct
32 Correct 47 ms 1816 KB Output is correct
33 Correct 51 ms 1816 KB Output is correct
34 Correct 49 ms 1816 KB Output is correct
35 Correct 50 ms 1816 KB Output is correct
36 Correct 47 ms 1816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 5 ms 1380 KB Output is correct
3 Correct 3 ms 1380 KB Output is correct
4 Correct 5 ms 1380 KB Output is correct
5 Correct 8 ms 1380 KB Output is correct
6 Correct 6 ms 1432 KB Output is correct
7 Correct 5 ms 1432 KB Output is correct
8 Correct 8 ms 1512 KB Output is correct
9 Correct 8 ms 1552 KB Output is correct
10 Correct 15 ms 1552 KB Output is correct
11 Correct 16 ms 1552 KB Output is correct
12 Correct 17 ms 1816 KB Output is correct
13 Correct 14 ms 1816 KB Output is correct
14 Correct 15 ms 1816 KB Output is correct
15 Correct 14 ms 1816 KB Output is correct
16 Correct 17 ms 1816 KB Output is correct
17 Correct 10 ms 1816 KB Output is correct
18 Correct 14 ms 1816 KB Output is correct
19 Correct 14 ms 1816 KB Output is correct
20 Correct 15 ms 1816 KB Output is correct
21 Correct 32 ms 1816 KB Output is correct
22 Correct 36 ms 1816 KB Output is correct
23 Correct 31 ms 1816 KB Output is correct
24 Correct 46 ms 1816 KB Output is correct
25 Correct 45 ms 1816 KB Output is correct
26 Correct 51 ms 1816 KB Output is correct
27 Correct 50 ms 1816 KB Output is correct
28 Correct 57 ms 1816 KB Output is correct
29 Correct 50 ms 1816 KB Output is correct
30 Correct 50 ms 1816 KB Output is correct
31 Correct 51 ms 1816 KB Output is correct
32 Correct 47 ms 1816 KB Output is correct
33 Correct 51 ms 1816 KB Output is correct
34 Correct 49 ms 1816 KB Output is correct
35 Correct 50 ms 1816 KB Output is correct
36 Correct 47 ms 1816 KB Output is correct
37 Correct 107 ms 1816 KB Output is correct
38 Correct 131 ms 1820 KB Output is correct
39 Correct 186 ms 1892 KB Output is correct
40 Correct 164 ms 1892 KB Output is correct
41 Correct 213 ms 1964 KB Output is correct
42 Correct 148 ms 1964 KB Output is correct
43 Correct 177 ms 1964 KB Output is correct
44 Correct 176 ms 1964 KB Output is correct
45 Correct 184 ms 2108 KB Output is correct
46 Correct 171 ms 2108 KB Output is correct
47 Correct 158 ms 2108 KB Output is correct
48 Correct 204 ms 2108 KB Output is correct
49 Correct 192 ms 2108 KB Output is correct
50 Correct 150 ms 2108 KB Output is correct
51 Correct 11 ms 2108 KB Output is correct
52 Correct 216 ms 2108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 5 ms 1380 KB Output is correct
3 Correct 3 ms 1380 KB Output is correct
4 Correct 5 ms 1380 KB Output is correct
5 Correct 8 ms 1380 KB Output is correct
6 Correct 6 ms 1432 KB Output is correct
7 Correct 5 ms 1432 KB Output is correct
8 Correct 8 ms 1512 KB Output is correct
9 Correct 8 ms 1552 KB Output is correct
10 Correct 15 ms 1552 KB Output is correct
11 Correct 16 ms 1552 KB Output is correct
12 Correct 17 ms 1816 KB Output is correct
13 Correct 14 ms 1816 KB Output is correct
14 Correct 15 ms 1816 KB Output is correct
15 Correct 14 ms 1816 KB Output is correct
16 Correct 17 ms 1816 KB Output is correct
17 Correct 10 ms 1816 KB Output is correct
18 Correct 14 ms 1816 KB Output is correct
19 Correct 14 ms 1816 KB Output is correct
20 Correct 15 ms 1816 KB Output is correct
21 Correct 32 ms 1816 KB Output is correct
22 Correct 36 ms 1816 KB Output is correct
23 Correct 31 ms 1816 KB Output is correct
24 Correct 46 ms 1816 KB Output is correct
25 Correct 45 ms 1816 KB Output is correct
26 Correct 51 ms 1816 KB Output is correct
27 Correct 50 ms 1816 KB Output is correct
28 Correct 57 ms 1816 KB Output is correct
29 Correct 50 ms 1816 KB Output is correct
30 Correct 50 ms 1816 KB Output is correct
31 Correct 51 ms 1816 KB Output is correct
32 Correct 47 ms 1816 KB Output is correct
33 Correct 51 ms 1816 KB Output is correct
34 Correct 49 ms 1816 KB Output is correct
35 Correct 50 ms 1816 KB Output is correct
36 Correct 47 ms 1816 KB Output is correct
37 Correct 107 ms 1816 KB Output is correct
38 Correct 131 ms 1820 KB Output is correct
39 Correct 186 ms 1892 KB Output is correct
40 Correct 164 ms 1892 KB Output is correct
41 Correct 213 ms 1964 KB Output is correct
42 Correct 148 ms 1964 KB Output is correct
43 Correct 177 ms 1964 KB Output is correct
44 Correct 176 ms 1964 KB Output is correct
45 Correct 184 ms 2108 KB Output is correct
46 Correct 171 ms 2108 KB Output is correct
47 Correct 158 ms 2108 KB Output is correct
48 Correct 204 ms 2108 KB Output is correct
49 Correct 192 ms 2108 KB Output is correct
50 Correct 150 ms 2108 KB Output is correct
51 Correct 11 ms 2108 KB Output is correct
52 Correct 216 ms 2108 KB Output is correct
53 Correct 194 ms 2108 KB Output is correct
54 Correct 249 ms 2108 KB Output is correct
55 Correct 361 ms 2384 KB Output is correct
56 Correct 229 ms 2384 KB Output is correct
57 Correct 353 ms 2492 KB Output is correct
58 Correct 261 ms 2492 KB Output is correct
59 Correct 285 ms 2492 KB Output is correct
60 Correct 23 ms 2492 KB Output is correct
61 Correct 303 ms 2492 KB Output is correct
62 Correct 299 ms 2500 KB Output is correct
63 Correct 307 ms 2500 KB Output is correct
64 Correct 292 ms 2500 KB Output is correct
65 Correct 231 ms 2500 KB Output is correct
66 Correct 217 ms 2500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 5 ms 1380 KB Output is correct
3 Correct 3 ms 1380 KB Output is correct
4 Correct 5 ms 1380 KB Output is correct
5 Correct 8 ms 1380 KB Output is correct
6 Correct 6 ms 1432 KB Output is correct
7 Correct 5 ms 1432 KB Output is correct
8 Correct 8 ms 1512 KB Output is correct
9 Correct 8 ms 1552 KB Output is correct
10 Correct 15 ms 1552 KB Output is correct
11 Correct 16 ms 1552 KB Output is correct
12 Correct 17 ms 1816 KB Output is correct
13 Correct 14 ms 1816 KB Output is correct
14 Correct 15 ms 1816 KB Output is correct
15 Correct 14 ms 1816 KB Output is correct
16 Correct 17 ms 1816 KB Output is correct
17 Correct 10 ms 1816 KB Output is correct
18 Correct 14 ms 1816 KB Output is correct
19 Correct 14 ms 1816 KB Output is correct
20 Correct 15 ms 1816 KB Output is correct
21 Correct 32 ms 1816 KB Output is correct
22 Correct 36 ms 1816 KB Output is correct
23 Correct 31 ms 1816 KB Output is correct
24 Correct 46 ms 1816 KB Output is correct
25 Correct 45 ms 1816 KB Output is correct
26 Correct 51 ms 1816 KB Output is correct
27 Correct 50 ms 1816 KB Output is correct
28 Correct 57 ms 1816 KB Output is correct
29 Correct 50 ms 1816 KB Output is correct
30 Correct 50 ms 1816 KB Output is correct
31 Correct 51 ms 1816 KB Output is correct
32 Correct 47 ms 1816 KB Output is correct
33 Correct 51 ms 1816 KB Output is correct
34 Correct 49 ms 1816 KB Output is correct
35 Correct 50 ms 1816 KB Output is correct
36 Correct 47 ms 1816 KB Output is correct
37 Correct 107 ms 1816 KB Output is correct
38 Correct 131 ms 1820 KB Output is correct
39 Correct 186 ms 1892 KB Output is correct
40 Correct 164 ms 1892 KB Output is correct
41 Correct 213 ms 1964 KB Output is correct
42 Correct 148 ms 1964 KB Output is correct
43 Correct 177 ms 1964 KB Output is correct
44 Correct 176 ms 1964 KB Output is correct
45 Correct 184 ms 2108 KB Output is correct
46 Correct 171 ms 2108 KB Output is correct
47 Correct 158 ms 2108 KB Output is correct
48 Correct 204 ms 2108 KB Output is correct
49 Correct 192 ms 2108 KB Output is correct
50 Correct 150 ms 2108 KB Output is correct
51 Correct 11 ms 2108 KB Output is correct
52 Correct 216 ms 2108 KB Output is correct
53 Correct 194 ms 2108 KB Output is correct
54 Correct 249 ms 2108 KB Output is correct
55 Correct 361 ms 2384 KB Output is correct
56 Correct 229 ms 2384 KB Output is correct
57 Correct 353 ms 2492 KB Output is correct
58 Correct 261 ms 2492 KB Output is correct
59 Correct 285 ms 2492 KB Output is correct
60 Correct 23 ms 2492 KB Output is correct
61 Correct 303 ms 2492 KB Output is correct
62 Correct 299 ms 2500 KB Output is correct
63 Correct 307 ms 2500 KB Output is correct
64 Correct 292 ms 2500 KB Output is correct
65 Correct 231 ms 2500 KB Output is correct
66 Correct 217 ms 2500 KB Output is correct
67 Correct 315 ms 2500 KB Output is correct
68 Correct 62 ms 2500 KB Output is correct
69 Correct 793 ms 3132 KB Output is correct
70 Correct 549 ms 3132 KB Output is correct
71 Correct 507 ms 3132 KB Output is correct
72 Correct 657 ms 3132 KB Output is correct
73 Correct 509 ms 3132 KB Output is correct
74 Correct 895 ms 3184 KB Output is correct
75 Correct 653 ms 3184 KB Output is correct
76 Correct 822 ms 3252 KB Output is correct
77 Correct 803 ms 3252 KB Output is correct