답안 #536918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536918 2022-03-14T07:35:25 Z akhan42 Bootfall (IZhO17_bootfall) C++17
100 / 100
748 ms 1104 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define F first
#define S second
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forbn(i, b, n) for(int i = b; i < n; ++i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define lc v << 1
#define rc (v << 1) + 1

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef complex<double> cd;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template <class T> inline void mineq(T &a, T b) { a = min(a, b); }
template <class T> inline void maxeq(T &a, T b) { a = max(a, b); }


const int BASE = 500;
const int MX = BASE * BASE + 1;
using bts = bitset<MX>;


void solve() {
	int n;
	cin >> n;

	vi arr(n);
	forn(i, n)
		cin >> arr[i];

	bts s;
	s[0] = 1;
	int total = 0;
	bool odd = true, even = true;
	for(int a: arr) {
		s |= s << a;
		total += a;
		if(a % 2)
			even = false;
		else
			odd = false;
	}

	if(total % 2 || s[total / 2] == 0 || (!even && !odd))
	{
		cout << 0;
		return;
	}

	vector<bool> used(501, false);

	bts ans;
	ans.flip();

	forn(i, n) {
		if(used[arr[i]]) continue;
		used[arr[i]] = true;

		bts w;
		w[0] = 1;
		forn(j, n) {
			if(i == j) continue;
			w |= w << arr[j];
		}

		int d = (total - arr[i]) / 2;

		ans &= w >> d;
	}

	ans[0] = 0;

	cout << ans.count() << '\n';
	for(int i = ans._Find_first(); i < sz(ans); i = ans._Find_next(i)) {
		cout << 2 * i - odd << ' ';
	}
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

//	freopen("triangles.in", "r", stdin);
//	freopen("triangles.out", "w", stdout);

	int t = 1;
//	cin >> t;
	while(t--) {
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 472 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 472 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 18 ms 468 KB Output is correct
22 Correct 16 ms 468 KB Output is correct
23 Correct 9 ms 472 KB Output is correct
24 Correct 23 ms 460 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 5 ms 468 KB Output is correct
27 Correct 5 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 20 ms 456 KB Output is correct
32 Correct 26 ms 444 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 4 ms 464 KB Output is correct
36 Correct 29 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 472 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 18 ms 468 KB Output is correct
22 Correct 16 ms 468 KB Output is correct
23 Correct 9 ms 472 KB Output is correct
24 Correct 23 ms 460 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 5 ms 468 KB Output is correct
27 Correct 5 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 20 ms 456 KB Output is correct
32 Correct 26 ms 444 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 4 ms 464 KB Output is correct
36 Correct 29 ms 460 KB Output is correct
37 Correct 56 ms 460 KB Output is correct
38 Correct 68 ms 448 KB Output is correct
39 Correct 4 ms 468 KB Output is correct
40 Correct 214 ms 448 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 167 ms 448 KB Output is correct
43 Correct 43 ms 576 KB Output is correct
44 Correct 42 ms 572 KB Output is correct
45 Correct 38 ms 588 KB Output is correct
46 Correct 223 ms 460 KB Output is correct
47 Correct 175 ms 444 KB Output is correct
48 Correct 11 ms 468 KB Output is correct
49 Correct 7 ms 468 KB Output is correct
50 Correct 178 ms 444 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 22 ms 584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 472 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 18 ms 468 KB Output is correct
22 Correct 16 ms 468 KB Output is correct
23 Correct 9 ms 472 KB Output is correct
24 Correct 23 ms 460 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 5 ms 468 KB Output is correct
27 Correct 5 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 20 ms 456 KB Output is correct
32 Correct 26 ms 444 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 4 ms 464 KB Output is correct
36 Correct 29 ms 460 KB Output is correct
37 Correct 56 ms 460 KB Output is correct
38 Correct 68 ms 448 KB Output is correct
39 Correct 4 ms 468 KB Output is correct
40 Correct 214 ms 448 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 167 ms 448 KB Output is correct
43 Correct 43 ms 576 KB Output is correct
44 Correct 42 ms 572 KB Output is correct
45 Correct 38 ms 588 KB Output is correct
46 Correct 223 ms 460 KB Output is correct
47 Correct 175 ms 444 KB Output is correct
48 Correct 11 ms 468 KB Output is correct
49 Correct 7 ms 468 KB Output is correct
50 Correct 178 ms 444 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 22 ms 584 KB Output is correct
53 Correct 206 ms 576 KB Output is correct
54 Correct 261 ms 576 KB Output is correct
55 Correct 45 ms 712 KB Output is correct
56 Correct 245 ms 600 KB Output is correct
57 Correct 48 ms 724 KB Output is correct
58 Correct 372 ms 576 KB Output is correct
59 Correct 194 ms 576 KB Output is correct
60 Correct 3 ms 468 KB Output is correct
61 Correct 200 ms 576 KB Output is correct
62 Correct 102 ms 708 KB Output is correct
63 Correct 58 ms 700 KB Output is correct
64 Correct 53 ms 712 KB Output is correct
65 Correct 18 ms 468 KB Output is correct
66 Correct 69 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 472 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 18 ms 468 KB Output is correct
22 Correct 16 ms 468 KB Output is correct
23 Correct 9 ms 472 KB Output is correct
24 Correct 23 ms 460 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 5 ms 468 KB Output is correct
27 Correct 5 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 20 ms 456 KB Output is correct
32 Correct 26 ms 444 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 4 ms 464 KB Output is correct
36 Correct 29 ms 460 KB Output is correct
37 Correct 56 ms 460 KB Output is correct
38 Correct 68 ms 448 KB Output is correct
39 Correct 4 ms 468 KB Output is correct
40 Correct 214 ms 448 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 167 ms 448 KB Output is correct
43 Correct 43 ms 576 KB Output is correct
44 Correct 42 ms 572 KB Output is correct
45 Correct 38 ms 588 KB Output is correct
46 Correct 223 ms 460 KB Output is correct
47 Correct 175 ms 444 KB Output is correct
48 Correct 11 ms 468 KB Output is correct
49 Correct 7 ms 468 KB Output is correct
50 Correct 178 ms 444 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 22 ms 584 KB Output is correct
53 Correct 206 ms 576 KB Output is correct
54 Correct 261 ms 576 KB Output is correct
55 Correct 45 ms 712 KB Output is correct
56 Correct 245 ms 600 KB Output is correct
57 Correct 48 ms 724 KB Output is correct
58 Correct 372 ms 576 KB Output is correct
59 Correct 194 ms 576 KB Output is correct
60 Correct 3 ms 468 KB Output is correct
61 Correct 200 ms 576 KB Output is correct
62 Correct 102 ms 708 KB Output is correct
63 Correct 58 ms 700 KB Output is correct
64 Correct 53 ms 712 KB Output is correct
65 Correct 18 ms 468 KB Output is correct
66 Correct 69 ms 468 KB Output is correct
67 Correct 488 ms 580 KB Output is correct
68 Correct 4 ms 468 KB Output is correct
69 Correct 87 ms 1104 KB Output is correct
70 Correct 747 ms 840 KB Output is correct
71 Correct 748 ms 840 KB Output is correct
72 Correct 3 ms 464 KB Output is correct
73 Correct 3 ms 468 KB Output is correct
74 Correct 156 ms 1096 KB Output is correct
75 Correct 442 ms 976 KB Output is correct
76 Correct 42 ms 1104 KB Output is correct
77 Correct 90 ms 1096 KB Output is correct