답안 #648644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648644 2022-10-07T09:14:15 Z ghostwriter Bootfall (IZhO17_bootfall) C++14
28 / 100
1000 ms 20464 KB
#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:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:56:2: note: in expansion of macro 'FOR'
   56 |  FOR(i, 1, n - 1) {
      |  ^~~
bootfall.cpp:34:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
bootfall.cpp:78:11: note: in expansion of macro 'FRN'
   78 |  if (inv) FRN(i, n) a[i] /= n;
      |           ^~~
bootfall.cpp: In function 'pn multiply(pn, pn)':
bootfall.cpp:34:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
bootfall.cpp:87:2: note: in expansion of macro 'FRN'
   87 |  FRN(i, n) a[i] *= b[i];
      |  ^~~
bootfall.cpp:34:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #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] = round(a[i].real());
      |  ^~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:102:5: note: in expansion of macro 'FOR'
  102 |     FOR(i, 1, n) {
      |     ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:111:5: note: in expansion of macro 'FOR'
  111 |     FOR(i, 1, n) d[i] = d[i - 1] | (d[i - 1] << a[i]);
      |     ^~~
bootfall.cpp:33:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   33 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
bootfall.cpp:116:5: note: in expansion of macro 'FOS'
  116 |     FOS(i, n, 1) d1[i] = d1[i + 1] | (d1[i + 1] << a[i]);
      |     ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:117:5: note: in expansion of macro 'FOR'
  117 |     FOR(i, 1, 500 * n) c[i] = 1;
      |     ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:118:5: note: in expansion of macro 'FOR'
  118 |     FOR(i, 1, n) {
      |     ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:120:6: note: in expansion of macro 'FOR'
  120 |      FOR(j, 0, 500 * (i - 1)) p[j] = d[i - 1][j];
      |      ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:121:6: note: in expansion of macro 'FOR'
  121 |      FOR(j, 0, 500 * (n - i)) p1[j] = d1[i + 1][j];
      |      ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #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, 1, 500 * n) {
      |      ^~~
bootfall.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bootfall.cpp:138:5: note: in expansion of macro 'FOR'
  138 |     FOR(i, 1, 500 * n) {
      |     ^~~
bootfall.cpp:36:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bootfall.cpp:143:5: note: in expansion of macro 'EACH'
  143 |     EACH(i, ans) cout << i << ' ';
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 3 ms 1012 KB Output is correct
3 Correct 1 ms 388 KB Output is correct
4 Correct 1 ms 776 KB Output is correct
5 Correct 12 ms 1700 KB Output is correct
6 Correct 5 ms 1216 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 11 ms 1684 KB Output is correct
9 Correct 10 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 3 ms 1012 KB Output is correct
3 Correct 1 ms 388 KB Output is correct
4 Correct 1 ms 776 KB Output is correct
5 Correct 12 ms 1700 KB Output is correct
6 Correct 5 ms 1216 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 11 ms 1684 KB Output is correct
9 Correct 10 ms 1492 KB Output is correct
10 Correct 59 ms 3312 KB Output is correct
11 Correct 57 ms 3312 KB Output is correct
12 Correct 58 ms 3328 KB Output is correct
13 Correct 50 ms 2976 KB Output is correct
14 Correct 57 ms 3148 KB Output is correct
15 Correct 68 ms 3176 KB Output is correct
16 Correct 59 ms 3284 KB Output is correct
17 Correct 37 ms 2416 KB Output is correct
18 Correct 46 ms 2808 KB Output is correct
19 Correct 50 ms 3020 KB Output is correct
20 Correct 64 ms 3368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 3 ms 1012 KB Output is correct
3 Correct 1 ms 388 KB Output is correct
4 Correct 1 ms 776 KB Output is correct
5 Correct 12 ms 1700 KB Output is correct
6 Correct 5 ms 1216 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 11 ms 1684 KB Output is correct
9 Correct 10 ms 1492 KB Output is correct
10 Correct 59 ms 3312 KB Output is correct
11 Correct 57 ms 3312 KB Output is correct
12 Correct 58 ms 3328 KB Output is correct
13 Correct 50 ms 2976 KB Output is correct
14 Correct 57 ms 3148 KB Output is correct
15 Correct 68 ms 3176 KB Output is correct
16 Correct 59 ms 3284 KB Output is correct
17 Correct 37 ms 2416 KB Output is correct
18 Correct 46 ms 2808 KB Output is correct
19 Correct 50 ms 3020 KB Output is correct
20 Correct 64 ms 3368 KB Output is correct
21 Correct 269 ms 6484 KB Output is correct
22 Correct 625 ms 8284 KB Output is correct
23 Correct 209 ms 5508 KB Output is correct
24 Correct 817 ms 9896 KB Output is correct
25 Correct 828 ms 10008 KB Output is correct
26 Correct 879 ms 10340 KB Output is correct
27 Correct 859 ms 10352 KB Output is correct
28 Correct 851 ms 10456 KB Output is correct
29 Correct 885 ms 10428 KB Output is correct
30 Correct 877 ms 10596 KB Output is correct
31 Correct 851 ms 10716 KB Output is correct
32 Correct 880 ms 10692 KB Output is correct
33 Correct 882 ms 10620 KB Output is correct
34 Correct 872 ms 10608 KB Output is correct
35 Correct 846 ms 10524 KB Output is correct
36 Correct 842 ms 10520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 3 ms 1012 KB Output is correct
3 Correct 1 ms 388 KB Output is correct
4 Correct 1 ms 776 KB Output is correct
5 Correct 12 ms 1700 KB Output is correct
6 Correct 5 ms 1216 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 11 ms 1684 KB Output is correct
9 Correct 10 ms 1492 KB Output is correct
10 Correct 59 ms 3312 KB Output is correct
11 Correct 57 ms 3312 KB Output is correct
12 Correct 58 ms 3328 KB Output is correct
13 Correct 50 ms 2976 KB Output is correct
14 Correct 57 ms 3148 KB Output is correct
15 Correct 68 ms 3176 KB Output is correct
16 Correct 59 ms 3284 KB Output is correct
17 Correct 37 ms 2416 KB Output is correct
18 Correct 46 ms 2808 KB Output is correct
19 Correct 50 ms 3020 KB Output is correct
20 Correct 64 ms 3368 KB Output is correct
21 Correct 269 ms 6484 KB Output is correct
22 Correct 625 ms 8284 KB Output is correct
23 Correct 209 ms 5508 KB Output is correct
24 Correct 817 ms 9896 KB Output is correct
25 Correct 828 ms 10008 KB Output is correct
26 Correct 879 ms 10340 KB Output is correct
27 Correct 859 ms 10352 KB Output is correct
28 Correct 851 ms 10456 KB Output is correct
29 Correct 885 ms 10428 KB Output is correct
30 Correct 877 ms 10596 KB Output is correct
31 Correct 851 ms 10716 KB Output is correct
32 Correct 880 ms 10692 KB Output is correct
33 Correct 882 ms 10620 KB Output is correct
34 Correct 872 ms 10608 KB Output is correct
35 Correct 846 ms 10524 KB Output is correct
36 Correct 842 ms 10520 KB Output is correct
37 Execution timed out 1094 ms 20464 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 3 ms 1012 KB Output is correct
3 Correct 1 ms 388 KB Output is correct
4 Correct 1 ms 776 KB Output is correct
5 Correct 12 ms 1700 KB Output is correct
6 Correct 5 ms 1216 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 11 ms 1684 KB Output is correct
9 Correct 10 ms 1492 KB Output is correct
10 Correct 59 ms 3312 KB Output is correct
11 Correct 57 ms 3312 KB Output is correct
12 Correct 58 ms 3328 KB Output is correct
13 Correct 50 ms 2976 KB Output is correct
14 Correct 57 ms 3148 KB Output is correct
15 Correct 68 ms 3176 KB Output is correct
16 Correct 59 ms 3284 KB Output is correct
17 Correct 37 ms 2416 KB Output is correct
18 Correct 46 ms 2808 KB Output is correct
19 Correct 50 ms 3020 KB Output is correct
20 Correct 64 ms 3368 KB Output is correct
21 Correct 269 ms 6484 KB Output is correct
22 Correct 625 ms 8284 KB Output is correct
23 Correct 209 ms 5508 KB Output is correct
24 Correct 817 ms 9896 KB Output is correct
25 Correct 828 ms 10008 KB Output is correct
26 Correct 879 ms 10340 KB Output is correct
27 Correct 859 ms 10352 KB Output is correct
28 Correct 851 ms 10456 KB Output is correct
29 Correct 885 ms 10428 KB Output is correct
30 Correct 877 ms 10596 KB Output is correct
31 Correct 851 ms 10716 KB Output is correct
32 Correct 880 ms 10692 KB Output is correct
33 Correct 882 ms 10620 KB Output is correct
34 Correct 872 ms 10608 KB Output is correct
35 Correct 846 ms 10524 KB Output is correct
36 Correct 842 ms 10520 KB Output is correct
37 Execution timed out 1094 ms 20464 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 3 ms 1012 KB Output is correct
3 Correct 1 ms 388 KB Output is correct
4 Correct 1 ms 776 KB Output is correct
5 Correct 12 ms 1700 KB Output is correct
6 Correct 5 ms 1216 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 11 ms 1684 KB Output is correct
9 Correct 10 ms 1492 KB Output is correct
10 Correct 59 ms 3312 KB Output is correct
11 Correct 57 ms 3312 KB Output is correct
12 Correct 58 ms 3328 KB Output is correct
13 Correct 50 ms 2976 KB Output is correct
14 Correct 57 ms 3148 KB Output is correct
15 Correct 68 ms 3176 KB Output is correct
16 Correct 59 ms 3284 KB Output is correct
17 Correct 37 ms 2416 KB Output is correct
18 Correct 46 ms 2808 KB Output is correct
19 Correct 50 ms 3020 KB Output is correct
20 Correct 64 ms 3368 KB Output is correct
21 Correct 269 ms 6484 KB Output is correct
22 Correct 625 ms 8284 KB Output is correct
23 Correct 209 ms 5508 KB Output is correct
24 Correct 817 ms 9896 KB Output is correct
25 Correct 828 ms 10008 KB Output is correct
26 Correct 879 ms 10340 KB Output is correct
27 Correct 859 ms 10352 KB Output is correct
28 Correct 851 ms 10456 KB Output is correct
29 Correct 885 ms 10428 KB Output is correct
30 Correct 877 ms 10596 KB Output is correct
31 Correct 851 ms 10716 KB Output is correct
32 Correct 880 ms 10692 KB Output is correct
33 Correct 882 ms 10620 KB Output is correct
34 Correct 872 ms 10608 KB Output is correct
35 Correct 846 ms 10524 KB Output is correct
36 Correct 842 ms 10520 KB Output is correct
37 Execution timed out 1094 ms 20464 KB Time limit exceeded
38 Halted 0 ms 0 KB -