답안 #648645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648645 2022-10-07T09:16:07 Z ghostwriter Bootfall (IZhO17_bootfall) C++17
28 / 100
1000 ms 20328 KB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#else
#define debug(...)
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) (x).bg(), (x).ed()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Tran The Bao - ghostwriter
    Training for VOI23 gold medal
----------------------------------------------------------------
    DIT ME CHUYEN BAO LOC
----------------------------------------------------------------
*/
const db PI = acos(-1);
typedef complex<double> cd;
typedef vector<cd> pn;
void fft(pn &a, bool inv) {
	int n = sz(a), rev = 0;
	FOR(i, 1, n - 1) {
		int j = n >> 1;
		WHILE(rev & j) {
			rev ^= j;
			j >>= 1;
		}
		rev ^= j;
		if (i < rev) swap(a[i], a[rev]);
	}
	for (int i = 2; i <= n; i <<= 1) {
		db ang = 2 * PI / i * (inv? -1 : 1);
		cd wn(cos(ang), sin(ang));
		for (int j = 0; j < n; j += i) {
			cd w(1);
			for (int z = 0; z < i / 2; ++z) {
				cd u = a[j + z], v = w * a[j + z + i / 2];
				a[j + z] = u + v;
				a[j + z + i / 2] = u - v;
				w *= wn;
			}
		}
	}
	if (inv) FRN(i, n) a[i] /= n;
}
pn multiply(pn a, pn b) {
	int n = 1;
	WHILE(n < sz(a) + sz(b)) n <<= 1;
	a.resize(n);
	b.resize(n);
	fft(a, 0);
	fft(b, 0);
	FRN(i, n) a[i] *= b[i];
	fft(a, 1);
	FRN(i, n) a[i] = round(a[i].real());
	return a;
}
const int N = 502;
const int NxN = 25e4 + 1;
int n, a[N], c[NxN], sum = 0;
bitset<NxN> d[N], d1[N];
vi ans;
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    cin >> n;
    FOR(i, 1, n) {
    	cin >> a[i];
    	sum += a[i];
    }
    if (sum & 1) {
    	cout << 0;
    	return 0;
    }
    d[0][0] = d1[n + 1][0] = 1;
    FOR(i, 1, n) d[i] = d[i - 1] | (d[i - 1] << a[i]);
    if (!d[n][sum / 2]) {
    	cout << 0;
    	return 0;
    }
    FOS(i, n, 1) d1[i] = d1[i + 1] | (d1[i + 1] << a[i]);
    FOR(i, 1, 500 * n) c[i] = 1;
    FOR(i, 1, n) {
    	pn p(500 * (i - 1) + 1, 0), p1(500 * (n - i) + 1, 0);
    	FOR(j, 0, 500 * (i - 1)) p[j] = d[i - 1][j];
    	FOR(j, 0, 500 * (n - i)) p1[j] = d1[i + 1][j];
    	p = multiply(p, p1);
    	FOR(j, 1, 500 * n) {
    		if (!c[j]) continue;
    		int tmp = sum + j - a[i];
    		if (tmp & 1) {
    			c[j] = 0;
    			continue;
    		}
    		tmp /= 2;
    		if (tmp >= sz(p)) c[j] = 0;
    		else {
    			tmp = p[tmp].real();
    			if (!tmp) c[j] = 0;
    		}
    	}
    }
    FOR(i, 1, 500 * n) {
    	if (!c[i]) continue;
    	ans.pb(i);
    }
    cout << sz(ans) << '\n';
    EACH(i, ans) cout << i << ' ';
    return 0;
}
/*
4
1 3 1 5
----------------------------------------------------------------
From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH
----------------------------------------------------------------
*/

Compilation message

bootfall.cpp: In function 'void fft(pn&, bool)':
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:58:2: note: in expansion of macro 'FOR'
   58 |  FOR(i, 1, n - 1) {
      |  ^~~
bootfall.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
bootfall.cpp:80:11: note: in expansion of macro 'FRN'
   80 |  if (inv) FRN(i, n) a[i] /= n;
      |           ^~~
bootfall.cpp: In function 'pn multiply(pn, pn)':
bootfall.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
bootfall.cpp:89:2: note: in expansion of macro 'FRN'
   89 |  FRN(i, n) a[i] *= b[i];
      |  ^~~
bootfall.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
bootfall.cpp:91:2: note: in expansion of macro 'FRN'
   91 |  FRN(i, n) a[i] = round(a[i].real());
      |  ^~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:104:5: note: in expansion of macro 'FOR'
  104 |     FOR(i, 1, n) {
      |     ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:113:5: note: in expansion of macro 'FOR'
  113 |     FOR(i, 1, n) d[i] = d[i - 1] | (d[i - 1] << a[i]);
      |     ^~~
bootfall.cpp:35:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   35 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
bootfall.cpp:118:5: note: in expansion of macro 'FOS'
  118 |     FOS(i, n, 1) d1[i] = d1[i + 1] | (d1[i + 1] << a[i]);
      |     ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:119:5: note: in expansion of macro 'FOR'
  119 |     FOR(i, 1, 500 * n) c[i] = 1;
      |     ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:120:5: note: in expansion of macro 'FOR'
  120 |     FOR(i, 1, n) {
      |     ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:122:6: note: in expansion of macro 'FOR'
  122 |      FOR(j, 0, 500 * (i - 1)) p[j] = d[i - 1][j];
      |      ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:123:6: note: in expansion of macro 'FOR'
  123 |      FOR(j, 0, 500 * (n - i)) p1[j] = d1[i + 1][j];
      |      ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:125:6: note: in expansion of macro 'FOR'
  125 |      FOR(j, 1, 500 * n) {
      |      ^~~
bootfall.cpp:34:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:140:5: note: in expansion of macro 'FOR'
  140 |     FOR(i, 1, 500 * n) {
      |     ^~~
bootfall.cpp:38:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   38 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bootfall.cpp:145:5: note: in expansion of macro 'EACH'
  145 |     EACH(i, ans) cout << i << ' ';
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 12 ms 1672 KB Output is correct
6 Correct 4 ms 1216 KB Output is correct
7 Correct 3 ms 1004 KB Output is correct
8 Correct 12 ms 1724 KB Output is correct
9 Correct 11 ms 1496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 12 ms 1672 KB Output is correct
6 Correct 4 ms 1216 KB Output is correct
7 Correct 3 ms 1004 KB Output is correct
8 Correct 12 ms 1724 KB Output is correct
9 Correct 11 ms 1496 KB Output is correct
10 Correct 60 ms 3284 KB Output is correct
11 Correct 63 ms 3304 KB Output is correct
12 Correct 56 ms 3296 KB Output is correct
13 Correct 51 ms 3020 KB Output is correct
14 Correct 72 ms 3232 KB Output is correct
15 Correct 53 ms 3148 KB Output is correct
16 Correct 57 ms 3308 KB Output is correct
17 Correct 34 ms 2340 KB Output is correct
18 Correct 46 ms 2812 KB Output is correct
19 Correct 50 ms 3012 KB Output is correct
20 Correct 58 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 12 ms 1672 KB Output is correct
6 Correct 4 ms 1216 KB Output is correct
7 Correct 3 ms 1004 KB Output is correct
8 Correct 12 ms 1724 KB Output is correct
9 Correct 11 ms 1496 KB Output is correct
10 Correct 60 ms 3284 KB Output is correct
11 Correct 63 ms 3304 KB Output is correct
12 Correct 56 ms 3296 KB Output is correct
13 Correct 51 ms 3020 KB Output is correct
14 Correct 72 ms 3232 KB Output is correct
15 Correct 53 ms 3148 KB Output is correct
16 Correct 57 ms 3308 KB Output is correct
17 Correct 34 ms 2340 KB Output is correct
18 Correct 46 ms 2812 KB Output is correct
19 Correct 50 ms 3012 KB Output is correct
20 Correct 58 ms 3320 KB Output is correct
21 Correct 283 ms 6560 KB Output is correct
22 Correct 625 ms 8320 KB Output is correct
23 Correct 197 ms 5700 KB Output is correct
24 Correct 855 ms 9980 KB Output is correct
25 Correct 855 ms 9976 KB Output is correct
26 Correct 896 ms 10728 KB Output is correct
27 Correct 892 ms 10600 KB Output is correct
28 Correct 884 ms 10596 KB Output is correct
29 Correct 927 ms 10560 KB Output is correct
30 Correct 864 ms 10400 KB Output is correct
31 Correct 881 ms 10420 KB Output is correct
32 Correct 887 ms 10560 KB Output is correct
33 Correct 858 ms 10472 KB Output is correct
34 Correct 863 ms 10428 KB Output is correct
35 Correct 969 ms 10564 KB Output is correct
36 Correct 947 ms 10416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 12 ms 1672 KB Output is correct
6 Correct 4 ms 1216 KB Output is correct
7 Correct 3 ms 1004 KB Output is correct
8 Correct 12 ms 1724 KB Output is correct
9 Correct 11 ms 1496 KB Output is correct
10 Correct 60 ms 3284 KB Output is correct
11 Correct 63 ms 3304 KB Output is correct
12 Correct 56 ms 3296 KB Output is correct
13 Correct 51 ms 3020 KB Output is correct
14 Correct 72 ms 3232 KB Output is correct
15 Correct 53 ms 3148 KB Output is correct
16 Correct 57 ms 3308 KB Output is correct
17 Correct 34 ms 2340 KB Output is correct
18 Correct 46 ms 2812 KB Output is correct
19 Correct 50 ms 3012 KB Output is correct
20 Correct 58 ms 3320 KB Output is correct
21 Correct 283 ms 6560 KB Output is correct
22 Correct 625 ms 8320 KB Output is correct
23 Correct 197 ms 5700 KB Output is correct
24 Correct 855 ms 9980 KB Output is correct
25 Correct 855 ms 9976 KB Output is correct
26 Correct 896 ms 10728 KB Output is correct
27 Correct 892 ms 10600 KB Output is correct
28 Correct 884 ms 10596 KB Output is correct
29 Correct 927 ms 10560 KB Output is correct
30 Correct 864 ms 10400 KB Output is correct
31 Correct 881 ms 10420 KB Output is correct
32 Correct 887 ms 10560 KB Output is correct
33 Correct 858 ms 10472 KB Output is correct
34 Correct 863 ms 10428 KB Output is correct
35 Correct 969 ms 10564 KB Output is correct
36 Correct 947 ms 10416 KB Output is correct
37 Execution timed out 1097 ms 20328 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 12 ms 1672 KB Output is correct
6 Correct 4 ms 1216 KB Output is correct
7 Correct 3 ms 1004 KB Output is correct
8 Correct 12 ms 1724 KB Output is correct
9 Correct 11 ms 1496 KB Output is correct
10 Correct 60 ms 3284 KB Output is correct
11 Correct 63 ms 3304 KB Output is correct
12 Correct 56 ms 3296 KB Output is correct
13 Correct 51 ms 3020 KB Output is correct
14 Correct 72 ms 3232 KB Output is correct
15 Correct 53 ms 3148 KB Output is correct
16 Correct 57 ms 3308 KB Output is correct
17 Correct 34 ms 2340 KB Output is correct
18 Correct 46 ms 2812 KB Output is correct
19 Correct 50 ms 3012 KB Output is correct
20 Correct 58 ms 3320 KB Output is correct
21 Correct 283 ms 6560 KB Output is correct
22 Correct 625 ms 8320 KB Output is correct
23 Correct 197 ms 5700 KB Output is correct
24 Correct 855 ms 9980 KB Output is correct
25 Correct 855 ms 9976 KB Output is correct
26 Correct 896 ms 10728 KB Output is correct
27 Correct 892 ms 10600 KB Output is correct
28 Correct 884 ms 10596 KB Output is correct
29 Correct 927 ms 10560 KB Output is correct
30 Correct 864 ms 10400 KB Output is correct
31 Correct 881 ms 10420 KB Output is correct
32 Correct 887 ms 10560 KB Output is correct
33 Correct 858 ms 10472 KB Output is correct
34 Correct 863 ms 10428 KB Output is correct
35 Correct 969 ms 10564 KB Output is correct
36 Correct 947 ms 10416 KB Output is correct
37 Execution timed out 1097 ms 20328 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 12 ms 1672 KB Output is correct
6 Correct 4 ms 1216 KB Output is correct
7 Correct 3 ms 1004 KB Output is correct
8 Correct 12 ms 1724 KB Output is correct
9 Correct 11 ms 1496 KB Output is correct
10 Correct 60 ms 3284 KB Output is correct
11 Correct 63 ms 3304 KB Output is correct
12 Correct 56 ms 3296 KB Output is correct
13 Correct 51 ms 3020 KB Output is correct
14 Correct 72 ms 3232 KB Output is correct
15 Correct 53 ms 3148 KB Output is correct
16 Correct 57 ms 3308 KB Output is correct
17 Correct 34 ms 2340 KB Output is correct
18 Correct 46 ms 2812 KB Output is correct
19 Correct 50 ms 3012 KB Output is correct
20 Correct 58 ms 3320 KB Output is correct
21 Correct 283 ms 6560 KB Output is correct
22 Correct 625 ms 8320 KB Output is correct
23 Correct 197 ms 5700 KB Output is correct
24 Correct 855 ms 9980 KB Output is correct
25 Correct 855 ms 9976 KB Output is correct
26 Correct 896 ms 10728 KB Output is correct
27 Correct 892 ms 10600 KB Output is correct
28 Correct 884 ms 10596 KB Output is correct
29 Correct 927 ms 10560 KB Output is correct
30 Correct 864 ms 10400 KB Output is correct
31 Correct 881 ms 10420 KB Output is correct
32 Correct 887 ms 10560 KB Output is correct
33 Correct 858 ms 10472 KB Output is correct
34 Correct 863 ms 10428 KB Output is correct
35 Correct 969 ms 10564 KB Output is correct
36 Correct 947 ms 10416 KB Output is correct
37 Execution timed out 1097 ms 20328 KB Time limit exceeded
38 Halted 0 ms 0 KB -