Submission #648713

# Submission time Handle Problem Language Result Execution time Memory
648713 2022-10-07T16:44:18 Z ghostwriter Bootfall (IZhO17_bootfall) C++14
100 / 100
719 ms 3472 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 int M = 1e9 + 7;
const int N = 502;
const int NxN = 25e4 + 1;
int n, a[N], c[NxN], d[NxN], sum = 0;
vi ans;
void add(int x) { FOS(i, NxN - 1, x) d[i] = (d[i] + d[i - x]) % M; }
void del(int x) { FOR(i, x, NxN - 1) d[i] = (d[i] - d[i - x] + M) % M; }
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] = 1;
    FOR(i, 1, n) add(a[i]);
    if (!d[sum / 2]) {
    	cout << 0;
    	return 0;
    }
    FOR(i, 1, NxN - 1) c[i] = 1;
    FOR(i, 1, n) {
    	del(a[i]);
    	FOR(j, 1, NxN - 1) {
    		if (!c[j]) continue;
    		int tmp = sum - a[i] + j;
    		if (tmp & 1) {
    			c[j] = 0;
    			continue;
    		}
    		if (!d[tmp / 2]) c[j] = 0;
    	}
    	add(a[i]);
    }
    FOR(i, 1, NxN - 1)
    	if (c[i])
    		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 add(int)':
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:56:19: note: in expansion of macro 'FOS'
   56 | void add(int x) { FOS(i, NxN - 1, x) d[i] = (d[i] + d[i - x]) % M; }
      |                   ^~~
bootfall.cpp: In function 'void del(int)':
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:57:19: note: in expansion of macro 'FOR'
   57 | void del(int x) { FOR(i, x, NxN - 1) d[i] = (d[i] - d[i - x] + M) % M; }
      |                   ^~~
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:63:5: note: in expansion of macro 'FOR'
   63 |     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:72:5: note: in expansion of macro 'FOR'
   72 |     FOR(i, 1, n) add(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:77:5: note: in expansion of macro 'FOR'
   77 |     FOR(i, 1, NxN - 1) 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:78:5: note: in expansion of macro 'FOR'
   78 |     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:80:6: note: in expansion of macro 'FOR'
   80 |      FOR(j, 1, NxN - 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:91:5: note: in expansion of macro 'FOR'
   91 |     FOR(i, 1, NxN - 1)
      |     ^~~
bootfall.cpp:36:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bootfall.cpp:95:5: note: in expansion of macro 'EACH'
   95 |     EACH(i, ans) cout << i << ' ';
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2260 KB Output is correct
2 Correct 13 ms 2260 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 8 ms 2280 KB Output is correct
5 Correct 19 ms 2260 KB Output is correct
6 Correct 14 ms 2260 KB Output is correct
7 Correct 10 ms 2260 KB Output is correct
8 Correct 19 ms 2284 KB Output is correct
9 Correct 15 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2260 KB Output is correct
2 Correct 13 ms 2260 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 8 ms 2280 KB Output is correct
5 Correct 19 ms 2260 KB Output is correct
6 Correct 14 ms 2260 KB Output is correct
7 Correct 10 ms 2260 KB Output is correct
8 Correct 19 ms 2284 KB Output is correct
9 Correct 15 ms 2260 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 48 ms 2204 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 41 ms 2260 KB Output is correct
14 Correct 43 ms 2212 KB Output is correct
15 Correct 44 ms 2260 KB Output is correct
16 Correct 51 ms 2268 KB Output is correct
17 Correct 28 ms 2204 KB Output is correct
18 Correct 34 ms 2260 KB Output is correct
19 Correct 39 ms 2260 KB Output is correct
20 Correct 42 ms 2204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2260 KB Output is correct
2 Correct 13 ms 2260 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 8 ms 2280 KB Output is correct
5 Correct 19 ms 2260 KB Output is correct
6 Correct 14 ms 2260 KB Output is correct
7 Correct 10 ms 2260 KB Output is correct
8 Correct 19 ms 2284 KB Output is correct
9 Correct 15 ms 2260 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 48 ms 2204 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 41 ms 2260 KB Output is correct
14 Correct 43 ms 2212 KB Output is correct
15 Correct 44 ms 2260 KB Output is correct
16 Correct 51 ms 2268 KB Output is correct
17 Correct 28 ms 2204 KB Output is correct
18 Correct 34 ms 2260 KB Output is correct
19 Correct 39 ms 2260 KB Output is correct
20 Correct 42 ms 2204 KB Output is correct
21 Correct 95 ms 2208 KB Output is correct
22 Correct 106 ms 2260 KB Output is correct
23 Correct 70 ms 2208 KB Output is correct
24 Correct 126 ms 2196 KB Output is correct
25 Correct 130 ms 2256 KB Output is correct
26 Correct 137 ms 2188 KB Output is correct
27 Correct 132 ms 2312 KB Output is correct
28 Correct 138 ms 2264 KB Output is correct
29 Correct 143 ms 2264 KB Output is correct
30 Correct 134 ms 2260 KB Output is correct
31 Correct 136 ms 2324 KB Output is correct
32 Correct 134 ms 2244 KB Output is correct
33 Correct 131 ms 2188 KB Output is correct
34 Correct 135 ms 2312 KB Output is correct
35 Correct 137 ms 2188 KB Output is correct
36 Correct 136 ms 2200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2260 KB Output is correct
2 Correct 13 ms 2260 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 8 ms 2280 KB Output is correct
5 Correct 19 ms 2260 KB Output is correct
6 Correct 14 ms 2260 KB Output is correct
7 Correct 10 ms 2260 KB Output is correct
8 Correct 19 ms 2284 KB Output is correct
9 Correct 15 ms 2260 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 48 ms 2204 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 41 ms 2260 KB Output is correct
14 Correct 43 ms 2212 KB Output is correct
15 Correct 44 ms 2260 KB Output is correct
16 Correct 51 ms 2268 KB Output is correct
17 Correct 28 ms 2204 KB Output is correct
18 Correct 34 ms 2260 KB Output is correct
19 Correct 39 ms 2260 KB Output is correct
20 Correct 42 ms 2204 KB Output is correct
21 Correct 95 ms 2208 KB Output is correct
22 Correct 106 ms 2260 KB Output is correct
23 Correct 70 ms 2208 KB Output is correct
24 Correct 126 ms 2196 KB Output is correct
25 Correct 130 ms 2256 KB Output is correct
26 Correct 137 ms 2188 KB Output is correct
27 Correct 132 ms 2312 KB Output is correct
28 Correct 138 ms 2264 KB Output is correct
29 Correct 143 ms 2264 KB Output is correct
30 Correct 134 ms 2260 KB Output is correct
31 Correct 136 ms 2324 KB Output is correct
32 Correct 134 ms 2244 KB Output is correct
33 Correct 131 ms 2188 KB Output is correct
34 Correct 135 ms 2312 KB Output is correct
35 Correct 137 ms 2188 KB Output is correct
36 Correct 136 ms 2200 KB Output is correct
37 Correct 279 ms 2388 KB Output is correct
38 Correct 266 ms 2456 KB Output is correct
39 Correct 321 ms 2192 KB Output is correct
40 Correct 362 ms 2396 KB Output is correct
41 Correct 366 ms 2200 KB Output is correct
42 Correct 340 ms 2508 KB Output is correct
43 Correct 327 ms 2592 KB Output is correct
44 Correct 333 ms 2752 KB Output is correct
45 Correct 333 ms 2712 KB Output is correct
46 Correct 366 ms 2316 KB Output is correct
47 Correct 335 ms 2448 KB Output is correct
48 Correct 330 ms 2580 KB Output is correct
49 Correct 328 ms 2316 KB Output is correct
50 Correct 344 ms 2456 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 366 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2260 KB Output is correct
2 Correct 13 ms 2260 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 8 ms 2280 KB Output is correct
5 Correct 19 ms 2260 KB Output is correct
6 Correct 14 ms 2260 KB Output is correct
7 Correct 10 ms 2260 KB Output is correct
8 Correct 19 ms 2284 KB Output is correct
9 Correct 15 ms 2260 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 48 ms 2204 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 41 ms 2260 KB Output is correct
14 Correct 43 ms 2212 KB Output is correct
15 Correct 44 ms 2260 KB Output is correct
16 Correct 51 ms 2268 KB Output is correct
17 Correct 28 ms 2204 KB Output is correct
18 Correct 34 ms 2260 KB Output is correct
19 Correct 39 ms 2260 KB Output is correct
20 Correct 42 ms 2204 KB Output is correct
21 Correct 95 ms 2208 KB Output is correct
22 Correct 106 ms 2260 KB Output is correct
23 Correct 70 ms 2208 KB Output is correct
24 Correct 126 ms 2196 KB Output is correct
25 Correct 130 ms 2256 KB Output is correct
26 Correct 137 ms 2188 KB Output is correct
27 Correct 132 ms 2312 KB Output is correct
28 Correct 138 ms 2264 KB Output is correct
29 Correct 143 ms 2264 KB Output is correct
30 Correct 134 ms 2260 KB Output is correct
31 Correct 136 ms 2324 KB Output is correct
32 Correct 134 ms 2244 KB Output is correct
33 Correct 131 ms 2188 KB Output is correct
34 Correct 135 ms 2312 KB Output is correct
35 Correct 137 ms 2188 KB Output is correct
36 Correct 136 ms 2200 KB Output is correct
37 Correct 279 ms 2388 KB Output is correct
38 Correct 266 ms 2456 KB Output is correct
39 Correct 321 ms 2192 KB Output is correct
40 Correct 362 ms 2396 KB Output is correct
41 Correct 366 ms 2200 KB Output is correct
42 Correct 340 ms 2508 KB Output is correct
43 Correct 327 ms 2592 KB Output is correct
44 Correct 333 ms 2752 KB Output is correct
45 Correct 333 ms 2712 KB Output is correct
46 Correct 366 ms 2316 KB Output is correct
47 Correct 335 ms 2448 KB Output is correct
48 Correct 330 ms 2580 KB Output is correct
49 Correct 328 ms 2316 KB Output is correct
50 Correct 344 ms 2456 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 366 ms 2648 KB Output is correct
53 Correct 435 ms 2512 KB Output is correct
54 Correct 468 ms 2568 KB Output is correct
55 Correct 479 ms 2848 KB Output is correct
56 Correct 420 ms 2692 KB Output is correct
57 Correct 477 ms 2840 KB Output is correct
58 Correct 480 ms 2576 KB Output is correct
59 Correct 469 ms 2768 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 477 ms 2776 KB Output is correct
62 Correct 448 ms 2832 KB Output is correct
63 Correct 438 ms 2768 KB Output is correct
64 Correct 420 ms 2832 KB Output is correct
65 Correct 423 ms 2200 KB Output is correct
66 Correct 413 ms 2316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2260 KB Output is correct
2 Correct 13 ms 2260 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 8 ms 2280 KB Output is correct
5 Correct 19 ms 2260 KB Output is correct
6 Correct 14 ms 2260 KB Output is correct
7 Correct 10 ms 2260 KB Output is correct
8 Correct 19 ms 2284 KB Output is correct
9 Correct 15 ms 2260 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 48 ms 2204 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 41 ms 2260 KB Output is correct
14 Correct 43 ms 2212 KB Output is correct
15 Correct 44 ms 2260 KB Output is correct
16 Correct 51 ms 2268 KB Output is correct
17 Correct 28 ms 2204 KB Output is correct
18 Correct 34 ms 2260 KB Output is correct
19 Correct 39 ms 2260 KB Output is correct
20 Correct 42 ms 2204 KB Output is correct
21 Correct 95 ms 2208 KB Output is correct
22 Correct 106 ms 2260 KB Output is correct
23 Correct 70 ms 2208 KB Output is correct
24 Correct 126 ms 2196 KB Output is correct
25 Correct 130 ms 2256 KB Output is correct
26 Correct 137 ms 2188 KB Output is correct
27 Correct 132 ms 2312 KB Output is correct
28 Correct 138 ms 2264 KB Output is correct
29 Correct 143 ms 2264 KB Output is correct
30 Correct 134 ms 2260 KB Output is correct
31 Correct 136 ms 2324 KB Output is correct
32 Correct 134 ms 2244 KB Output is correct
33 Correct 131 ms 2188 KB Output is correct
34 Correct 135 ms 2312 KB Output is correct
35 Correct 137 ms 2188 KB Output is correct
36 Correct 136 ms 2200 KB Output is correct
37 Correct 279 ms 2388 KB Output is correct
38 Correct 266 ms 2456 KB Output is correct
39 Correct 321 ms 2192 KB Output is correct
40 Correct 362 ms 2396 KB Output is correct
41 Correct 366 ms 2200 KB Output is correct
42 Correct 340 ms 2508 KB Output is correct
43 Correct 327 ms 2592 KB Output is correct
44 Correct 333 ms 2752 KB Output is correct
45 Correct 333 ms 2712 KB Output is correct
46 Correct 366 ms 2316 KB Output is correct
47 Correct 335 ms 2448 KB Output is correct
48 Correct 330 ms 2580 KB Output is correct
49 Correct 328 ms 2316 KB Output is correct
50 Correct 344 ms 2456 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 366 ms 2648 KB Output is correct
53 Correct 435 ms 2512 KB Output is correct
54 Correct 468 ms 2568 KB Output is correct
55 Correct 479 ms 2848 KB Output is correct
56 Correct 420 ms 2692 KB Output is correct
57 Correct 477 ms 2840 KB Output is correct
58 Correct 480 ms 2576 KB Output is correct
59 Correct 469 ms 2768 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 477 ms 2776 KB Output is correct
62 Correct 448 ms 2832 KB Output is correct
63 Correct 438 ms 2768 KB Output is correct
64 Correct 420 ms 2832 KB Output is correct
65 Correct 423 ms 2200 KB Output is correct
66 Correct 413 ms 2316 KB Output is correct
67 Correct 543 ms 2780 KB Output is correct
68 Correct 177 ms 1360 KB Output is correct
69 Correct 694 ms 3412 KB Output is correct
70 Correct 689 ms 3032 KB Output is correct
71 Correct 684 ms 3036 KB Output is correct
72 Correct 652 ms 2380 KB Output is correct
73 Correct 654 ms 2264 KB Output is correct
74 Correct 719 ms 3416 KB Output is correct
75 Correct 699 ms 3288 KB Output is correct
76 Correct 712 ms 3468 KB Output is correct
77 Correct 696 ms 3472 KB Output is correct