Submission #536114

# Submission time Handle Problem Language Result Execution time Memory
536114 2022-03-12T11:46:24 Z akhan42 Bootfall (IZhO17_bootfall) C++17
28 / 100
1000 ms 11512 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 double PI = acos(-1);


void fft(vector<cd> & a, bool invert) {
    int n = a.size();

    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1) {
    	double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1, 0);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}


vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < sz(a) + sz(b))
        n <<= 1;

    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}


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


int last_bit(bts& a) {
	int i = a._Find_first();
	while(a._Find_next(i) != sz(a))
		i = a._Find_next(i);
	return i;
}


bts sum(bts& a, bts& b) {
	int al = last_bit(a), bl = last_bit(b);

	vi v1, v2;
	forn(i, al + 1)
	v1.pb(a[i]);

	forn(i, bl + 1)
	v2.pb(b[i]);

	vi c = multiply(v1, v2);
	bts res;
	forn(i, min(sz(c), MX))
		if(c[i] > 0)
			res[i] = 1;
	return res;
}


void solve() {
	int n;
	cin >> n;
	vi arr(n);
	forn(i, n)
	cin >> arr[i];
	sort(all(arr));

	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;
	}

	bts empt; empt[0] = 1;
	vector<bts> pref(1, empt), suf(1, empt);

	forn(i, n) {
		bts bs = pref.back();
		pref.pb(bs | (bs << arr[i]));

		bs = suf.back();
		suf.pb(bs | (bs << arr[sz(arr) - 1 - i]));
	}

	bts ans;
	ans.flip();
	forn(i, n) {
		bts c = sum(pref[i], suf[n - 1 - i]);

		int d = (total - arr[i] - (odd ? 1 : 0)) / 2;

		ans &= c >> d;
	}

	vi vans;
	forbn(i, 1, MX) {
		if(ans[i]) {
			vans.pb(2 * i - (odd ? 1 : 0));
		}
	}

	cout << sz(vans) << '\n';
	for(int el: vans)
		cout << el << ' ';
}


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();
	}
}

Compilation message

bootfall.cpp: In function 'int last_bit(bts&)':
bootfall.cpp:100:24: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |  while(a._Find_next(i) != sz(a))
      |                        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 960 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 3 ms 960 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 960 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 3 ms 960 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 4 ms 1616 KB Output is correct
11 Correct 2 ms 1596 KB Output is correct
12 Correct 4 ms 1616 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 1616 KB Output is correct
15 Correct 2 ms 1616 KB Output is correct
16 Correct 3 ms 1616 KB Output is correct
17 Correct 2 ms 1360 KB Output is correct
18 Correct 3 ms 1488 KB Output is correct
19 Correct 2 ms 1488 KB Output is correct
20 Correct 5 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 960 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 3 ms 960 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 4 ms 1616 KB Output is correct
11 Correct 2 ms 1596 KB Output is correct
12 Correct 4 ms 1616 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 1616 KB Output is correct
15 Correct 2 ms 1616 KB Output is correct
16 Correct 3 ms 1616 KB Output is correct
17 Correct 2 ms 1360 KB Output is correct
18 Correct 3 ms 1488 KB Output is correct
19 Correct 2 ms 1488 KB Output is correct
20 Correct 5 ms 1616 KB Output is correct
21 Correct 28 ms 3664 KB Output is correct
22 Correct 33 ms 3664 KB Output is correct
23 Correct 22 ms 2316 KB Output is correct
24 Correct 84 ms 3664 KB Output is correct
25 Correct 177 ms 4068 KB Output is correct
26 Correct 219 ms 4248 KB Output is correct
27 Correct 187 ms 4348 KB Output is correct
28 Correct 180 ms 4240 KB Output is correct
29 Correct 204 ms 4364 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 93 ms 3900 KB Output is correct
32 Correct 92 ms 3852 KB Output is correct
33 Correct 198 ms 4264 KB Output is correct
34 Correct 184 ms 4260 KB Output is correct
35 Correct 188 ms 4256 KB Output is correct
36 Correct 92 ms 3852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 960 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 3 ms 960 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 4 ms 1616 KB Output is correct
11 Correct 2 ms 1596 KB Output is correct
12 Correct 4 ms 1616 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 1616 KB Output is correct
15 Correct 2 ms 1616 KB Output is correct
16 Correct 3 ms 1616 KB Output is correct
17 Correct 2 ms 1360 KB Output is correct
18 Correct 3 ms 1488 KB Output is correct
19 Correct 2 ms 1488 KB Output is correct
20 Correct 5 ms 1616 KB Output is correct
21 Correct 28 ms 3664 KB Output is correct
22 Correct 33 ms 3664 KB Output is correct
23 Correct 22 ms 2316 KB Output is correct
24 Correct 84 ms 3664 KB Output is correct
25 Correct 177 ms 4068 KB Output is correct
26 Correct 219 ms 4248 KB Output is correct
27 Correct 187 ms 4348 KB Output is correct
28 Correct 180 ms 4240 KB Output is correct
29 Correct 204 ms 4364 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 93 ms 3900 KB Output is correct
32 Correct 92 ms 3852 KB Output is correct
33 Correct 198 ms 4264 KB Output is correct
34 Correct 184 ms 4260 KB Output is correct
35 Correct 188 ms 4256 KB Output is correct
36 Correct 92 ms 3852 KB Output is correct
37 Correct 807 ms 8048 KB Output is correct
38 Correct 811 ms 8168 KB Output is correct
39 Execution timed out 1082 ms 11512 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 960 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 3 ms 960 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 4 ms 1616 KB Output is correct
11 Correct 2 ms 1596 KB Output is correct
12 Correct 4 ms 1616 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 1616 KB Output is correct
15 Correct 2 ms 1616 KB Output is correct
16 Correct 3 ms 1616 KB Output is correct
17 Correct 2 ms 1360 KB Output is correct
18 Correct 3 ms 1488 KB Output is correct
19 Correct 2 ms 1488 KB Output is correct
20 Correct 5 ms 1616 KB Output is correct
21 Correct 28 ms 3664 KB Output is correct
22 Correct 33 ms 3664 KB Output is correct
23 Correct 22 ms 2316 KB Output is correct
24 Correct 84 ms 3664 KB Output is correct
25 Correct 177 ms 4068 KB Output is correct
26 Correct 219 ms 4248 KB Output is correct
27 Correct 187 ms 4348 KB Output is correct
28 Correct 180 ms 4240 KB Output is correct
29 Correct 204 ms 4364 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 93 ms 3900 KB Output is correct
32 Correct 92 ms 3852 KB Output is correct
33 Correct 198 ms 4264 KB Output is correct
34 Correct 184 ms 4260 KB Output is correct
35 Correct 188 ms 4256 KB Output is correct
36 Correct 92 ms 3852 KB Output is correct
37 Correct 807 ms 8048 KB Output is correct
38 Correct 811 ms 8168 KB Output is correct
39 Execution timed out 1082 ms 11512 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 960 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 3 ms 960 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 4 ms 1616 KB Output is correct
11 Correct 2 ms 1596 KB Output is correct
12 Correct 4 ms 1616 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 1616 KB Output is correct
15 Correct 2 ms 1616 KB Output is correct
16 Correct 3 ms 1616 KB Output is correct
17 Correct 2 ms 1360 KB Output is correct
18 Correct 3 ms 1488 KB Output is correct
19 Correct 2 ms 1488 KB Output is correct
20 Correct 5 ms 1616 KB Output is correct
21 Correct 28 ms 3664 KB Output is correct
22 Correct 33 ms 3664 KB Output is correct
23 Correct 22 ms 2316 KB Output is correct
24 Correct 84 ms 3664 KB Output is correct
25 Correct 177 ms 4068 KB Output is correct
26 Correct 219 ms 4248 KB Output is correct
27 Correct 187 ms 4348 KB Output is correct
28 Correct 180 ms 4240 KB Output is correct
29 Correct 204 ms 4364 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 93 ms 3900 KB Output is correct
32 Correct 92 ms 3852 KB Output is correct
33 Correct 198 ms 4264 KB Output is correct
34 Correct 184 ms 4260 KB Output is correct
35 Correct 188 ms 4256 KB Output is correct
36 Correct 92 ms 3852 KB Output is correct
37 Correct 807 ms 8048 KB Output is correct
38 Correct 811 ms 8168 KB Output is correct
39 Execution timed out 1082 ms 11512 KB Time limit exceeded
40 Halted 0 ms 0 KB -