Submission #555339

# Submission time Handle Problem Language Result Execution time Memory
555339 2022-04-30T14:10:12 Z ngpin04 Bootfall (IZhO17_bootfall) C++14
100 / 100
115 ms 3528 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define ALL(x) (x).begin(), (x).end() 
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
const int N = 25e4 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);

bitset <N> dp;

int a[N];
int n, tot;

int cnt[2 * N];

void solve(int l, int r, bitset <N> &dp) {
	if (l == r) {
		for (int i = 0; i <= (tot >> 1); i++) {
			int x = i;
			int y = tot - i - a[l];
			if (x <= y)
				cnt[y - x] += dp[i];
		}

		// cerr << "left " << l << "\n";
		// for (int i = 0; i <= (tot >> 1); i++)
		// 	if (dp[i])
		// 		cerr << i << " ";
		// cerr << "\n";
		return;
	}

	int mid = (l + r) >> 1;
	
	bitset <N> tmp = dp;
	for (int i = l; i <= mid; i++)
		tmp |= (tmp << a[i]);
	
	solve(mid + 1, r, tmp);

	for (int i = mid + 1; i <= r; i++)
		dp |= (dp << a[i]);
	solve(l, mid, dp);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef ONLINE_JUDGE
	// freopen(TASK".inp","r",stdin);
	// freopen(TASK".out","w",stdout);
	#endif
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	tot = accumulate(a + 1, a + n + 1, 0);
	dp[0] = true;
	for (int i = 1; i <= n; i++)
		dp |= (dp << a[i]);

	if ((tot & 1) || !dp[tot >> 1])
		return cout << 0, 0;

	dp.reset();
	dp[0] = 1;

	solve(1, n, dp);

	vector <int> res;
	for (int i = 1; i <= tot; i++)
		if (cnt[i] == n)
			res.push_back(i);

	cout << res.size() << "\n";
	for (int x : res)
		cout << x << " ";
	return 0;	
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 772 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 772 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 772 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 772 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 3 ms 880 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 900 KB Output is correct
17 Correct 1 ms 900 KB Output is correct
18 Correct 2 ms 980 KB Output is correct
19 Correct 2 ms 928 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 772 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 772 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 3 ms 880 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 900 KB Output is correct
17 Correct 1 ms 900 KB Output is correct
18 Correct 2 ms 980 KB Output is correct
19 Correct 2 ms 928 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 5 ms 1108 KB Output is correct
22 Correct 5 ms 1160 KB Output is correct
23 Correct 4 ms 1032 KB Output is correct
24 Correct 7 ms 1108 KB Output is correct
25 Correct 7 ms 1156 KB Output is correct
26 Correct 7 ms 1236 KB Output is correct
27 Correct 7 ms 1156 KB Output is correct
28 Correct 7 ms 1108 KB Output is correct
29 Correct 8 ms 1236 KB Output is correct
30 Correct 7 ms 1156 KB Output is correct
31 Correct 7 ms 1236 KB Output is correct
32 Correct 8 ms 1108 KB Output is correct
33 Correct 8 ms 1108 KB Output is correct
34 Correct 7 ms 1152 KB Output is correct
35 Correct 7 ms 1156 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 772 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 772 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 3 ms 880 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 900 KB Output is correct
17 Correct 1 ms 900 KB Output is correct
18 Correct 2 ms 980 KB Output is correct
19 Correct 2 ms 928 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 5 ms 1108 KB Output is correct
22 Correct 5 ms 1160 KB Output is correct
23 Correct 4 ms 1032 KB Output is correct
24 Correct 7 ms 1108 KB Output is correct
25 Correct 7 ms 1156 KB Output is correct
26 Correct 7 ms 1236 KB Output is correct
27 Correct 7 ms 1156 KB Output is correct
28 Correct 7 ms 1108 KB Output is correct
29 Correct 8 ms 1236 KB Output is correct
30 Correct 7 ms 1156 KB Output is correct
31 Correct 7 ms 1236 KB Output is correct
32 Correct 8 ms 1108 KB Output is correct
33 Correct 8 ms 1108 KB Output is correct
34 Correct 7 ms 1152 KB Output is correct
35 Correct 7 ms 1156 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 21 ms 1364 KB Output is correct
38 Correct 17 ms 1452 KB Output is correct
39 Correct 28 ms 1492 KB Output is correct
40 Correct 28 ms 1592 KB Output is correct
41 Correct 33 ms 1632 KB Output is correct
42 Correct 25 ms 1480 KB Output is correct
43 Correct 32 ms 1712 KB Output is correct
44 Correct 36 ms 1716 KB Output is correct
45 Correct 28 ms 1724 KB Output is correct
46 Correct 25 ms 1364 KB Output is correct
47 Correct 22 ms 1492 KB Output is correct
48 Correct 27 ms 1800 KB Output is correct
49 Correct 26 ms 1488 KB Output is correct
50 Correct 23 ms 1568 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 31 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 772 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 772 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 3 ms 880 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 900 KB Output is correct
17 Correct 1 ms 900 KB Output is correct
18 Correct 2 ms 980 KB Output is correct
19 Correct 2 ms 928 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 5 ms 1108 KB Output is correct
22 Correct 5 ms 1160 KB Output is correct
23 Correct 4 ms 1032 KB Output is correct
24 Correct 7 ms 1108 KB Output is correct
25 Correct 7 ms 1156 KB Output is correct
26 Correct 7 ms 1236 KB Output is correct
27 Correct 7 ms 1156 KB Output is correct
28 Correct 7 ms 1108 KB Output is correct
29 Correct 8 ms 1236 KB Output is correct
30 Correct 7 ms 1156 KB Output is correct
31 Correct 7 ms 1236 KB Output is correct
32 Correct 8 ms 1108 KB Output is correct
33 Correct 8 ms 1108 KB Output is correct
34 Correct 7 ms 1152 KB Output is correct
35 Correct 7 ms 1156 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 21 ms 1364 KB Output is correct
38 Correct 17 ms 1452 KB Output is correct
39 Correct 28 ms 1492 KB Output is correct
40 Correct 28 ms 1592 KB Output is correct
41 Correct 33 ms 1632 KB Output is correct
42 Correct 25 ms 1480 KB Output is correct
43 Correct 32 ms 1712 KB Output is correct
44 Correct 36 ms 1716 KB Output is correct
45 Correct 28 ms 1724 KB Output is correct
46 Correct 25 ms 1364 KB Output is correct
47 Correct 22 ms 1492 KB Output is correct
48 Correct 27 ms 1800 KB Output is correct
49 Correct 26 ms 1488 KB Output is correct
50 Correct 23 ms 1568 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 31 ms 1996 KB Output is correct
53 Correct 31 ms 1764 KB Output is correct
54 Correct 41 ms 1932 KB Output is correct
55 Correct 55 ms 2272 KB Output is correct
56 Correct 34 ms 1868 KB Output is correct
57 Correct 59 ms 2432 KB Output is correct
58 Correct 42 ms 1884 KB Output is correct
59 Correct 51 ms 2028 KB Output is correct
60 Correct 3 ms 340 KB Output is correct
61 Correct 46 ms 2192 KB Output is correct
62 Correct 44 ms 2216 KB Output is correct
63 Correct 44 ms 2252 KB Output is correct
64 Correct 50 ms 2256 KB Output is correct
65 Correct 31 ms 1432 KB Output is correct
66 Correct 32 ms 1552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 772 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 772 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 3 ms 880 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 900 KB Output is correct
17 Correct 1 ms 900 KB Output is correct
18 Correct 2 ms 980 KB Output is correct
19 Correct 2 ms 928 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 5 ms 1108 KB Output is correct
22 Correct 5 ms 1160 KB Output is correct
23 Correct 4 ms 1032 KB Output is correct
24 Correct 7 ms 1108 KB Output is correct
25 Correct 7 ms 1156 KB Output is correct
26 Correct 7 ms 1236 KB Output is correct
27 Correct 7 ms 1156 KB Output is correct
28 Correct 7 ms 1108 KB Output is correct
29 Correct 8 ms 1236 KB Output is correct
30 Correct 7 ms 1156 KB Output is correct
31 Correct 7 ms 1236 KB Output is correct
32 Correct 8 ms 1108 KB Output is correct
33 Correct 8 ms 1108 KB Output is correct
34 Correct 7 ms 1152 KB Output is correct
35 Correct 7 ms 1156 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 21 ms 1364 KB Output is correct
38 Correct 17 ms 1452 KB Output is correct
39 Correct 28 ms 1492 KB Output is correct
40 Correct 28 ms 1592 KB Output is correct
41 Correct 33 ms 1632 KB Output is correct
42 Correct 25 ms 1480 KB Output is correct
43 Correct 32 ms 1712 KB Output is correct
44 Correct 36 ms 1716 KB Output is correct
45 Correct 28 ms 1724 KB Output is correct
46 Correct 25 ms 1364 KB Output is correct
47 Correct 22 ms 1492 KB Output is correct
48 Correct 27 ms 1800 KB Output is correct
49 Correct 26 ms 1488 KB Output is correct
50 Correct 23 ms 1568 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 31 ms 1996 KB Output is correct
53 Correct 31 ms 1764 KB Output is correct
54 Correct 41 ms 1932 KB Output is correct
55 Correct 55 ms 2272 KB Output is correct
56 Correct 34 ms 1868 KB Output is correct
57 Correct 59 ms 2432 KB Output is correct
58 Correct 42 ms 1884 KB Output is correct
59 Correct 51 ms 2028 KB Output is correct
60 Correct 3 ms 340 KB Output is correct
61 Correct 46 ms 2192 KB Output is correct
62 Correct 44 ms 2216 KB Output is correct
63 Correct 44 ms 2252 KB Output is correct
64 Correct 50 ms 2256 KB Output is correct
65 Correct 31 ms 1432 KB Output is correct
66 Correct 32 ms 1552 KB Output is correct
67 Correct 51 ms 2128 KB Output is correct
68 Correct 4 ms 436 KB Output is correct
69 Correct 108 ms 3308 KB Output is correct
70 Correct 77 ms 2492 KB Output is correct
71 Correct 78 ms 2468 KB Output is correct
72 Correct 72 ms 1820 KB Output is correct
73 Correct 71 ms 1812 KB Output is correct
74 Correct 110 ms 3352 KB Output is correct
75 Correct 92 ms 3036 KB Output is correct
76 Correct 115 ms 3436 KB Output is correct
77 Correct 113 ms 3528 KB Output is correct