Submission #418063

# Submission time Handle Problem Language Result Execution time Memory
418063 2021-06-05T01:52:26 Z JerryLiu06 Bootfall (IZhO17_bootfall) C++17
100 / 100
578 ms 2756 KB
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using db = double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define mp make_pair
#define f first
#define s second
 
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define EACH(a,x) for (auto& a: x)
 
const int MOD = 1e9 + 7;
const int MX = 510;
const ll INF = 1e18;

int N, A[MX], tot; int DP[MX * MX]; bitset<MX * MX> ans;

void ADD(int val) {
    tot += val; ROF(i, val, MX * MX) {
        DP[i] += DP[i - val]; if (DP[i] > MOD) DP[i] -= MOD;
    }
}
void DEL(int val) {
    tot -= val; FOR(i, val, MX * MX) {
        DP[i] -= DP[i - val]; if (DP[i] < 0) DP[i] += MOD;
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    ans.flip(); cin >> N; DP[0] = 1; F0R(i, N) cin >> A[i], ADD(A[i]);
    
    // Case when Tima is the recorder
    if (tot % 2 == 1 || !DP[tot / 2]) { cout << "0" << "\n"; return 0; }

    F0R(i, N) {
        DEL(A[i]); bitset<MX * MX> cur;

        F0R(j, tot / 2 + 1) if (DP[j]) cur[tot - 2 * j] = 1; ADD(A[i]); ans &= cur;
    }
    vi res; FOR(i, 1, MX * MX) if (ans[i]) res.pb(i); cout << sz(res) << "\n"; EACH(i, res) cout << i << " ";
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:39:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   39 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                    ^~~
bootfall.cpp:40:18: note: in expansion of macro 'FOR'
   40 | #define F0R(i,a) FOR(i,0,a)
      |                  ^~~
bootfall.cpp:73:9: note: in expansion of macro 'F0R'
   73 |         F0R(j, tot / 2 + 1) if (DP[j]) cur[tot - 2 * j] = 1; ADD(A[i]); ans &= cur;
      |         ^~~
bootfall.cpp:73:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   73 |         F0R(j, tot / 2 + 1) if (DP[j]) cur[tot - 2 * j] = 1; ADD(A[i]); ans &= cur;
      |                                                              ^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1356 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 5 ms 1356 KB Output is correct
5 Correct 12 ms 1396 KB Output is correct
6 Correct 8 ms 1280 KB Output is correct
7 Correct 7 ms 1356 KB Output is correct
8 Correct 12 ms 1356 KB Output is correct
9 Correct 10 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1356 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 5 ms 1356 KB Output is correct
5 Correct 12 ms 1396 KB Output is correct
6 Correct 8 ms 1280 KB Output is correct
7 Correct 7 ms 1356 KB Output is correct
8 Correct 12 ms 1356 KB Output is correct
9 Correct 10 ms 1356 KB Output is correct
10 Correct 26 ms 1284 KB Output is correct
11 Correct 29 ms 1284 KB Output is correct
12 Correct 27 ms 1280 KB Output is correct
13 Correct 24 ms 1392 KB Output is correct
14 Correct 26 ms 1404 KB Output is correct
15 Correct 34 ms 1380 KB Output is correct
16 Correct 39 ms 1356 KB Output is correct
17 Correct 22 ms 1356 KB Output is correct
18 Correct 23 ms 1396 KB Output is correct
19 Correct 24 ms 1356 KB Output is correct
20 Correct 26 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1356 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 5 ms 1356 KB Output is correct
5 Correct 12 ms 1396 KB Output is correct
6 Correct 8 ms 1280 KB Output is correct
7 Correct 7 ms 1356 KB Output is correct
8 Correct 12 ms 1356 KB Output is correct
9 Correct 10 ms 1356 KB Output is correct
10 Correct 26 ms 1284 KB Output is correct
11 Correct 29 ms 1284 KB Output is correct
12 Correct 27 ms 1280 KB Output is correct
13 Correct 24 ms 1392 KB Output is correct
14 Correct 26 ms 1404 KB Output is correct
15 Correct 34 ms 1380 KB Output is correct
16 Correct 39 ms 1356 KB Output is correct
17 Correct 22 ms 1356 KB Output is correct
18 Correct 23 ms 1396 KB Output is correct
19 Correct 24 ms 1356 KB Output is correct
20 Correct 26 ms 1356 KB Output is correct
21 Correct 56 ms 1384 KB Output is correct
22 Correct 64 ms 1384 KB Output is correct
23 Correct 46 ms 1388 KB Output is correct
24 Correct 85 ms 1376 KB Output is correct
25 Correct 79 ms 1356 KB Output is correct
26 Correct 94 ms 1376 KB Output is correct
27 Correct 84 ms 1392 KB Output is correct
28 Correct 83 ms 1388 KB Output is correct
29 Correct 86 ms 1392 KB Output is correct
30 Correct 87 ms 1356 KB Output is correct
31 Correct 84 ms 1476 KB Output is correct
32 Correct 85 ms 1372 KB Output is correct
33 Correct 84 ms 1372 KB Output is correct
34 Correct 83 ms 1372 KB Output is correct
35 Correct 84 ms 1356 KB Output is correct
36 Correct 89 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1356 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 5 ms 1356 KB Output is correct
5 Correct 12 ms 1396 KB Output is correct
6 Correct 8 ms 1280 KB Output is correct
7 Correct 7 ms 1356 KB Output is correct
8 Correct 12 ms 1356 KB Output is correct
9 Correct 10 ms 1356 KB Output is correct
10 Correct 26 ms 1284 KB Output is correct
11 Correct 29 ms 1284 KB Output is correct
12 Correct 27 ms 1280 KB Output is correct
13 Correct 24 ms 1392 KB Output is correct
14 Correct 26 ms 1404 KB Output is correct
15 Correct 34 ms 1380 KB Output is correct
16 Correct 39 ms 1356 KB Output is correct
17 Correct 22 ms 1356 KB Output is correct
18 Correct 23 ms 1396 KB Output is correct
19 Correct 24 ms 1356 KB Output is correct
20 Correct 26 ms 1356 KB Output is correct
21 Correct 56 ms 1384 KB Output is correct
22 Correct 64 ms 1384 KB Output is correct
23 Correct 46 ms 1388 KB Output is correct
24 Correct 85 ms 1376 KB Output is correct
25 Correct 79 ms 1356 KB Output is correct
26 Correct 94 ms 1376 KB Output is correct
27 Correct 84 ms 1392 KB Output is correct
28 Correct 83 ms 1388 KB Output is correct
29 Correct 86 ms 1392 KB Output is correct
30 Correct 87 ms 1356 KB Output is correct
31 Correct 84 ms 1476 KB Output is correct
32 Correct 85 ms 1372 KB Output is correct
33 Correct 84 ms 1372 KB Output is correct
34 Correct 83 ms 1372 KB Output is correct
35 Correct 84 ms 1356 KB Output is correct
36 Correct 89 ms 1388 KB Output is correct
37 Correct 169 ms 1500 KB Output is correct
38 Correct 169 ms 1512 KB Output is correct
39 Correct 206 ms 1380 KB Output is correct
40 Correct 232 ms 1516 KB Output is correct
41 Correct 229 ms 1356 KB Output is correct
42 Correct 233 ms 1504 KB Output is correct
43 Correct 217 ms 1768 KB Output is correct
44 Correct 217 ms 1852 KB Output is correct
45 Correct 221 ms 1760 KB Output is correct
46 Correct 228 ms 1356 KB Output is correct
47 Correct 214 ms 1504 KB Output is correct
48 Correct 224 ms 1652 KB Output is correct
49 Correct 211 ms 1392 KB Output is correct
50 Correct 214 ms 1504 KB Output is correct
51 Correct 73 ms 1380 KB Output is correct
52 Correct 241 ms 1760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1356 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 5 ms 1356 KB Output is correct
5 Correct 12 ms 1396 KB Output is correct
6 Correct 8 ms 1280 KB Output is correct
7 Correct 7 ms 1356 KB Output is correct
8 Correct 12 ms 1356 KB Output is correct
9 Correct 10 ms 1356 KB Output is correct
10 Correct 26 ms 1284 KB Output is correct
11 Correct 29 ms 1284 KB Output is correct
12 Correct 27 ms 1280 KB Output is correct
13 Correct 24 ms 1392 KB Output is correct
14 Correct 26 ms 1404 KB Output is correct
15 Correct 34 ms 1380 KB Output is correct
16 Correct 39 ms 1356 KB Output is correct
17 Correct 22 ms 1356 KB Output is correct
18 Correct 23 ms 1396 KB Output is correct
19 Correct 24 ms 1356 KB Output is correct
20 Correct 26 ms 1356 KB Output is correct
21 Correct 56 ms 1384 KB Output is correct
22 Correct 64 ms 1384 KB Output is correct
23 Correct 46 ms 1388 KB Output is correct
24 Correct 85 ms 1376 KB Output is correct
25 Correct 79 ms 1356 KB Output is correct
26 Correct 94 ms 1376 KB Output is correct
27 Correct 84 ms 1392 KB Output is correct
28 Correct 83 ms 1388 KB Output is correct
29 Correct 86 ms 1392 KB Output is correct
30 Correct 87 ms 1356 KB Output is correct
31 Correct 84 ms 1476 KB Output is correct
32 Correct 85 ms 1372 KB Output is correct
33 Correct 84 ms 1372 KB Output is correct
34 Correct 83 ms 1372 KB Output is correct
35 Correct 84 ms 1356 KB Output is correct
36 Correct 89 ms 1388 KB Output is correct
37 Correct 169 ms 1500 KB Output is correct
38 Correct 169 ms 1512 KB Output is correct
39 Correct 206 ms 1380 KB Output is correct
40 Correct 232 ms 1516 KB Output is correct
41 Correct 229 ms 1356 KB Output is correct
42 Correct 233 ms 1504 KB Output is correct
43 Correct 217 ms 1768 KB Output is correct
44 Correct 217 ms 1852 KB Output is correct
45 Correct 221 ms 1760 KB Output is correct
46 Correct 228 ms 1356 KB Output is correct
47 Correct 214 ms 1504 KB Output is correct
48 Correct 224 ms 1652 KB Output is correct
49 Correct 211 ms 1392 KB Output is correct
50 Correct 214 ms 1504 KB Output is correct
51 Correct 73 ms 1380 KB Output is correct
52 Correct 241 ms 1760 KB Output is correct
53 Correct 261 ms 1628 KB Output is correct
54 Correct 316 ms 1780 KB Output is correct
55 Correct 327 ms 1892 KB Output is correct
56 Correct 272 ms 1860 KB Output is correct
57 Correct 344 ms 2020 KB Output is correct
58 Correct 325 ms 1760 KB Output is correct
59 Correct 319 ms 1760 KB Output is correct
60 Correct 102 ms 1352 KB Output is correct
61 Correct 330 ms 1908 KB Output is correct
62 Correct 312 ms 1896 KB Output is correct
63 Correct 298 ms 1892 KB Output is correct
64 Correct 314 ms 1888 KB Output is correct
65 Correct 259 ms 1392 KB Output is correct
66 Correct 262 ms 1380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1356 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 5 ms 1356 KB Output is correct
5 Correct 12 ms 1396 KB Output is correct
6 Correct 8 ms 1280 KB Output is correct
7 Correct 7 ms 1356 KB Output is correct
8 Correct 12 ms 1356 KB Output is correct
9 Correct 10 ms 1356 KB Output is correct
10 Correct 26 ms 1284 KB Output is correct
11 Correct 29 ms 1284 KB Output is correct
12 Correct 27 ms 1280 KB Output is correct
13 Correct 24 ms 1392 KB Output is correct
14 Correct 26 ms 1404 KB Output is correct
15 Correct 34 ms 1380 KB Output is correct
16 Correct 39 ms 1356 KB Output is correct
17 Correct 22 ms 1356 KB Output is correct
18 Correct 23 ms 1396 KB Output is correct
19 Correct 24 ms 1356 KB Output is correct
20 Correct 26 ms 1356 KB Output is correct
21 Correct 56 ms 1384 KB Output is correct
22 Correct 64 ms 1384 KB Output is correct
23 Correct 46 ms 1388 KB Output is correct
24 Correct 85 ms 1376 KB Output is correct
25 Correct 79 ms 1356 KB Output is correct
26 Correct 94 ms 1376 KB Output is correct
27 Correct 84 ms 1392 KB Output is correct
28 Correct 83 ms 1388 KB Output is correct
29 Correct 86 ms 1392 KB Output is correct
30 Correct 87 ms 1356 KB Output is correct
31 Correct 84 ms 1476 KB Output is correct
32 Correct 85 ms 1372 KB Output is correct
33 Correct 84 ms 1372 KB Output is correct
34 Correct 83 ms 1372 KB Output is correct
35 Correct 84 ms 1356 KB Output is correct
36 Correct 89 ms 1388 KB Output is correct
37 Correct 169 ms 1500 KB Output is correct
38 Correct 169 ms 1512 KB Output is correct
39 Correct 206 ms 1380 KB Output is correct
40 Correct 232 ms 1516 KB Output is correct
41 Correct 229 ms 1356 KB Output is correct
42 Correct 233 ms 1504 KB Output is correct
43 Correct 217 ms 1768 KB Output is correct
44 Correct 217 ms 1852 KB Output is correct
45 Correct 221 ms 1760 KB Output is correct
46 Correct 228 ms 1356 KB Output is correct
47 Correct 214 ms 1504 KB Output is correct
48 Correct 224 ms 1652 KB Output is correct
49 Correct 211 ms 1392 KB Output is correct
50 Correct 214 ms 1504 KB Output is correct
51 Correct 73 ms 1380 KB Output is correct
52 Correct 241 ms 1760 KB Output is correct
53 Correct 261 ms 1628 KB Output is correct
54 Correct 316 ms 1780 KB Output is correct
55 Correct 327 ms 1892 KB Output is correct
56 Correct 272 ms 1860 KB Output is correct
57 Correct 344 ms 2020 KB Output is correct
58 Correct 325 ms 1760 KB Output is correct
59 Correct 319 ms 1760 KB Output is correct
60 Correct 102 ms 1352 KB Output is correct
61 Correct 330 ms 1908 KB Output is correct
62 Correct 312 ms 1896 KB Output is correct
63 Correct 298 ms 1892 KB Output is correct
64 Correct 314 ms 1888 KB Output is correct
65 Correct 259 ms 1392 KB Output is correct
66 Correct 262 ms 1380 KB Output is correct
67 Correct 400 ms 1896 KB Output is correct
68 Correct 146 ms 1376 KB Output is correct
69 Correct 535 ms 2528 KB Output is correct
70 Correct 503 ms 2156 KB Output is correct
71 Correct 483 ms 2148 KB Output is correct
72 Correct 478 ms 1356 KB Output is correct
73 Correct 490 ms 1476 KB Output is correct
74 Correct 562 ms 2528 KB Output is correct
75 Correct 517 ms 2400 KB Output is correct
76 Correct 543 ms 2528 KB Output is correct
77 Correct 578 ms 2756 KB Output is correct