Submission #501748

# Submission time Handle Problem Language Result Execution time Memory
501748 2022-01-04T13:17:23 Z shmad Bootfall (IZhO17_bootfall) C++17
100 / 100
663 ms 15984 KB
#include <bits/stdc++.h>

#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvi = vt< vt<int> >;

const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 60);
const double eps = 1e-6;

int dp[250000];

void solve () {
	int n;
	cin >> n;
	vt<int> a(n + 1);
	int sum = 0;
	for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
	if (n & 1) cout << "0\n", exit(0);
	set<int> ans;
	vt<int> used(N, 0);
	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int w = 500 * 500; w >= a[i]; w--) dp[w] += dp[w - a[i]];
	}
	for (int i = 1; i <= n; i++) {
		for (int w = a[i]; w < 500 * 500; w++) dp[w] -= dp[w - a[i]];
		for (int val = 1; val <= sum; val++) {
			int s = sum - a[i];
			s += val;
			if (s & 1) continue;
			if (dp[s / 2]) {
				used[val]++;
				if (used[val] >= n) ans.insert(val);
			}
		}
		for (int w = 500 * 500; w >= a[i]; w--) dp[w] += dp[w - a[i]];
	}
	cout << sz(ans) << '\n';
	for (auto x: ans) cout << x << ' ';
	cout << '\n';
}

bool testcases = 0;
                  
signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int test = 1;
    if (testcases) cin >> test;
    for (int cs = 1; cs <= test; cs++) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10044 KB Output is correct
2 Correct 7 ms 10060 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 7 ms 10060 KB Output is correct
5 Correct 11 ms 10112 KB Output is correct
6 Correct 9 ms 10060 KB Output is correct
7 Correct 7 ms 10060 KB Output is correct
8 Correct 11 ms 10112 KB Output is correct
9 Correct 12 ms 10060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10044 KB Output is correct
2 Correct 7 ms 10060 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 7 ms 10060 KB Output is correct
5 Correct 11 ms 10112 KB Output is correct
6 Correct 9 ms 10060 KB Output is correct
7 Correct 7 ms 10060 KB Output is correct
8 Correct 11 ms 10112 KB Output is correct
9 Correct 12 ms 10060 KB Output is correct
10 Correct 20 ms 10060 KB Output is correct
11 Correct 21 ms 10060 KB Output is correct
12 Correct 20 ms 10060 KB Output is correct
13 Correct 18 ms 10060 KB Output is correct
14 Correct 19 ms 10040 KB Output is correct
15 Correct 20 ms 10112 KB Output is correct
16 Correct 23 ms 10060 KB Output is correct
17 Correct 14 ms 10060 KB Output is correct
18 Correct 17 ms 10116 KB Output is correct
19 Correct 18 ms 10060 KB Output is correct
20 Correct 19 ms 10060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10044 KB Output is correct
2 Correct 7 ms 10060 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 7 ms 10060 KB Output is correct
5 Correct 11 ms 10112 KB Output is correct
6 Correct 9 ms 10060 KB Output is correct
7 Correct 7 ms 10060 KB Output is correct
8 Correct 11 ms 10112 KB Output is correct
9 Correct 12 ms 10060 KB Output is correct
10 Correct 20 ms 10060 KB Output is correct
11 Correct 21 ms 10060 KB Output is correct
12 Correct 20 ms 10060 KB Output is correct
13 Correct 18 ms 10060 KB Output is correct
14 Correct 19 ms 10040 KB Output is correct
15 Correct 20 ms 10112 KB Output is correct
16 Correct 23 ms 10060 KB Output is correct
17 Correct 14 ms 10060 KB Output is correct
18 Correct 17 ms 10116 KB Output is correct
19 Correct 18 ms 10060 KB Output is correct
20 Correct 19 ms 10060 KB Output is correct
21 Correct 50 ms 10092 KB Output is correct
22 Correct 66 ms 10092 KB Output is correct
23 Correct 32 ms 10108 KB Output is correct
24 Correct 57 ms 10100 KB Output is correct
25 Correct 56 ms 10224 KB Output is correct
26 Correct 83 ms 10216 KB Output is correct
27 Correct 64 ms 10092 KB Output is correct
28 Correct 59 ms 10188 KB Output is correct
29 Correct 57 ms 10096 KB Output is correct
30 Correct 57 ms 10060 KB Output is correct
31 Correct 63 ms 10216 KB Output is correct
32 Correct 58 ms 10108 KB Output is correct
33 Correct 57 ms 10092 KB Output is correct
34 Correct 60 ms 10088 KB Output is correct
35 Correct 61 ms 10172 KB Output is correct
36 Correct 58 ms 10104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10044 KB Output is correct
2 Correct 7 ms 10060 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 7 ms 10060 KB Output is correct
5 Correct 11 ms 10112 KB Output is correct
6 Correct 9 ms 10060 KB Output is correct
7 Correct 7 ms 10060 KB Output is correct
8 Correct 11 ms 10112 KB Output is correct
9 Correct 12 ms 10060 KB Output is correct
10 Correct 20 ms 10060 KB Output is correct
11 Correct 21 ms 10060 KB Output is correct
12 Correct 20 ms 10060 KB Output is correct
13 Correct 18 ms 10060 KB Output is correct
14 Correct 19 ms 10040 KB Output is correct
15 Correct 20 ms 10112 KB Output is correct
16 Correct 23 ms 10060 KB Output is correct
17 Correct 14 ms 10060 KB Output is correct
18 Correct 17 ms 10116 KB Output is correct
19 Correct 18 ms 10060 KB Output is correct
20 Correct 19 ms 10060 KB Output is correct
21 Correct 50 ms 10092 KB Output is correct
22 Correct 66 ms 10092 KB Output is correct
23 Correct 32 ms 10108 KB Output is correct
24 Correct 57 ms 10100 KB Output is correct
25 Correct 56 ms 10224 KB Output is correct
26 Correct 83 ms 10216 KB Output is correct
27 Correct 64 ms 10092 KB Output is correct
28 Correct 59 ms 10188 KB Output is correct
29 Correct 57 ms 10096 KB Output is correct
30 Correct 57 ms 10060 KB Output is correct
31 Correct 63 ms 10216 KB Output is correct
32 Correct 58 ms 10108 KB Output is correct
33 Correct 57 ms 10092 KB Output is correct
34 Correct 60 ms 10088 KB Output is correct
35 Correct 61 ms 10172 KB Output is correct
36 Correct 58 ms 10104 KB Output is correct
37 Correct 118 ms 10476 KB Output is correct
38 Correct 118 ms 10488 KB Output is correct
39 Correct 184 ms 10100 KB Output is correct
40 Correct 196 ms 10868 KB Output is correct
41 Correct 192 ms 10096 KB Output is correct
42 Correct 161 ms 10864 KB Output is correct
43 Correct 185 ms 11376 KB Output is correct
44 Correct 189 ms 11376 KB Output is correct
45 Correct 176 ms 11360 KB Output is correct
46 Correct 164 ms 10048 KB Output is correct
47 Correct 167 ms 10856 KB Output is correct
48 Correct 178 ms 10984 KB Output is correct
49 Correct 173 ms 10344 KB Output is correct
50 Correct 161 ms 10860 KB Output is correct
51 Correct 150 ms 10060 KB Output is correct
52 Correct 223 ms 11504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10044 KB Output is correct
2 Correct 7 ms 10060 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 7 ms 10060 KB Output is correct
5 Correct 11 ms 10112 KB Output is correct
6 Correct 9 ms 10060 KB Output is correct
7 Correct 7 ms 10060 KB Output is correct
8 Correct 11 ms 10112 KB Output is correct
9 Correct 12 ms 10060 KB Output is correct
10 Correct 20 ms 10060 KB Output is correct
11 Correct 21 ms 10060 KB Output is correct
12 Correct 20 ms 10060 KB Output is correct
13 Correct 18 ms 10060 KB Output is correct
14 Correct 19 ms 10040 KB Output is correct
15 Correct 20 ms 10112 KB Output is correct
16 Correct 23 ms 10060 KB Output is correct
17 Correct 14 ms 10060 KB Output is correct
18 Correct 17 ms 10116 KB Output is correct
19 Correct 18 ms 10060 KB Output is correct
20 Correct 19 ms 10060 KB Output is correct
21 Correct 50 ms 10092 KB Output is correct
22 Correct 66 ms 10092 KB Output is correct
23 Correct 32 ms 10108 KB Output is correct
24 Correct 57 ms 10100 KB Output is correct
25 Correct 56 ms 10224 KB Output is correct
26 Correct 83 ms 10216 KB Output is correct
27 Correct 64 ms 10092 KB Output is correct
28 Correct 59 ms 10188 KB Output is correct
29 Correct 57 ms 10096 KB Output is correct
30 Correct 57 ms 10060 KB Output is correct
31 Correct 63 ms 10216 KB Output is correct
32 Correct 58 ms 10108 KB Output is correct
33 Correct 57 ms 10092 KB Output is correct
34 Correct 60 ms 10088 KB Output is correct
35 Correct 61 ms 10172 KB Output is correct
36 Correct 58 ms 10104 KB Output is correct
37 Correct 118 ms 10476 KB Output is correct
38 Correct 118 ms 10488 KB Output is correct
39 Correct 184 ms 10100 KB Output is correct
40 Correct 196 ms 10868 KB Output is correct
41 Correct 192 ms 10096 KB Output is correct
42 Correct 161 ms 10864 KB Output is correct
43 Correct 185 ms 11376 KB Output is correct
44 Correct 189 ms 11376 KB Output is correct
45 Correct 176 ms 11360 KB Output is correct
46 Correct 164 ms 10048 KB Output is correct
47 Correct 167 ms 10856 KB Output is correct
48 Correct 178 ms 10984 KB Output is correct
49 Correct 173 ms 10344 KB Output is correct
50 Correct 161 ms 10860 KB Output is correct
51 Correct 150 ms 10060 KB Output is correct
52 Correct 223 ms 11504 KB Output is correct
53 Correct 253 ms 11248 KB Output is correct
54 Correct 244 ms 11504 KB Output is correct
55 Correct 300 ms 12660 KB Output is correct
56 Correct 242 ms 11516 KB Output is correct
57 Correct 326 ms 12792 KB Output is correct
58 Correct 281 ms 11632 KB Output is correct
59 Correct 308 ms 12012 KB Output is correct
60 Correct 258 ms 10060 KB Output is correct
61 Correct 302 ms 12272 KB Output is correct
62 Correct 266 ms 12528 KB Output is correct
63 Correct 275 ms 12528 KB Output is correct
64 Correct 269 ms 12528 KB Output is correct
65 Correct 206 ms 10092 KB Output is correct
66 Correct 212 ms 10348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10044 KB Output is correct
2 Correct 7 ms 10060 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 7 ms 10060 KB Output is correct
5 Correct 11 ms 10112 KB Output is correct
6 Correct 9 ms 10060 KB Output is correct
7 Correct 7 ms 10060 KB Output is correct
8 Correct 11 ms 10112 KB Output is correct
9 Correct 12 ms 10060 KB Output is correct
10 Correct 20 ms 10060 KB Output is correct
11 Correct 21 ms 10060 KB Output is correct
12 Correct 20 ms 10060 KB Output is correct
13 Correct 18 ms 10060 KB Output is correct
14 Correct 19 ms 10040 KB Output is correct
15 Correct 20 ms 10112 KB Output is correct
16 Correct 23 ms 10060 KB Output is correct
17 Correct 14 ms 10060 KB Output is correct
18 Correct 17 ms 10116 KB Output is correct
19 Correct 18 ms 10060 KB Output is correct
20 Correct 19 ms 10060 KB Output is correct
21 Correct 50 ms 10092 KB Output is correct
22 Correct 66 ms 10092 KB Output is correct
23 Correct 32 ms 10108 KB Output is correct
24 Correct 57 ms 10100 KB Output is correct
25 Correct 56 ms 10224 KB Output is correct
26 Correct 83 ms 10216 KB Output is correct
27 Correct 64 ms 10092 KB Output is correct
28 Correct 59 ms 10188 KB Output is correct
29 Correct 57 ms 10096 KB Output is correct
30 Correct 57 ms 10060 KB Output is correct
31 Correct 63 ms 10216 KB Output is correct
32 Correct 58 ms 10108 KB Output is correct
33 Correct 57 ms 10092 KB Output is correct
34 Correct 60 ms 10088 KB Output is correct
35 Correct 61 ms 10172 KB Output is correct
36 Correct 58 ms 10104 KB Output is correct
37 Correct 118 ms 10476 KB Output is correct
38 Correct 118 ms 10488 KB Output is correct
39 Correct 184 ms 10100 KB Output is correct
40 Correct 196 ms 10868 KB Output is correct
41 Correct 192 ms 10096 KB Output is correct
42 Correct 161 ms 10864 KB Output is correct
43 Correct 185 ms 11376 KB Output is correct
44 Correct 189 ms 11376 KB Output is correct
45 Correct 176 ms 11360 KB Output is correct
46 Correct 164 ms 10048 KB Output is correct
47 Correct 167 ms 10856 KB Output is correct
48 Correct 178 ms 10984 KB Output is correct
49 Correct 173 ms 10344 KB Output is correct
50 Correct 161 ms 10860 KB Output is correct
51 Correct 150 ms 10060 KB Output is correct
52 Correct 223 ms 11504 KB Output is correct
53 Correct 253 ms 11248 KB Output is correct
54 Correct 244 ms 11504 KB Output is correct
55 Correct 300 ms 12660 KB Output is correct
56 Correct 242 ms 11516 KB Output is correct
57 Correct 326 ms 12792 KB Output is correct
58 Correct 281 ms 11632 KB Output is correct
59 Correct 308 ms 12012 KB Output is correct
60 Correct 258 ms 10060 KB Output is correct
61 Correct 302 ms 12272 KB Output is correct
62 Correct 266 ms 12528 KB Output is correct
63 Correct 275 ms 12528 KB Output is correct
64 Correct 269 ms 12528 KB Output is correct
65 Correct 206 ms 10092 KB Output is correct
66 Correct 212 ms 10348 KB Output is correct
67 Correct 298 ms 12144 KB Output is correct
68 Correct 421 ms 10060 KB Output is correct
69 Correct 598 ms 15332 KB Output is correct
70 Correct 470 ms 13512 KB Output is correct
71 Correct 442 ms 13296 KB Output is correct
72 Correct 426 ms 10048 KB Output is correct
73 Correct 0 ms 204 KB Output is correct
74 Correct 663 ms 15860 KB Output is correct
75 Correct 530 ms 14660 KB Output is correct
76 Correct 606 ms 15472 KB Output is correct
77 Correct 631 ms 15984 KB Output is correct