Submission #727934

# Submission time Handle Problem Language Result Execution time Memory
727934 2023-04-21T15:42:01 Z dxz05 Bootfall (IZhO17_bootfall) C++17
100 / 100
676 ms 2980 KB
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
//#define endl '\n'

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 502;
const int M = N * N;

int a[N];

void solve(){
    int n;
    cin >> n;

    vector<int> dp(M, 0);
    dp[0] = 1;
    for (int i = 1; i <= n; i++){
        cin >> a[i];

        for (int x = M - 1; x >= a[i]; x--){
            dp[x] += dp[x - a[i]];
            if (dp[x] >= MOD) dp[x] -= MOD;
        }

    }

    int sum = accumulate(a + 1, a + n + 1, 0);

    if (sum % 2 == 1 || dp[sum / 2] == 0){
        cout << 0 << endl;
        return;
    }

    vector<int> cnt(M, 0);

    for (int i = 1; i <= n; i++){
        for (int x = a[i]; x < M; x++){
            dp[x] -= dp[x - a[i]];
            if (dp[x] < 0) dp[x] += MOD;
        }

        for (int t = 1; t < M; t++){
            int s = sum - a[i] + t;
            if (s % 2) continue;
            s /= 2;

            if (dp[s] || s >= t && dp[s - t]) cnt[t]++;

        }

        for (int x = M - 1; x >= a[i]; x--){
            dp[x] += dp[x - a[i]];
            if (dp[x] >= MOD) dp[x] -= MOD;
        }
    }

    int ans = count(all(cnt), n);

    cout << ans << endl;
    for (int i = 1; i < M; i++){
        if (cnt[i] == n){
            cout << i << ' ';
        }
    }
    cout << endl;

}

int main(){
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int test_cases = 1;
    // cin >> test_cases;

    for (int test = 1; test <= test_cases; test++){
        // cout << (solve() ? "YES" : "NO") << endl;
        solve();
    }

    cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;

    return 0;
}

Compilation message

bootfall.cpp: In function 'void solve()':
bootfall.cpp:60:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   60 |             if (dp[s] || s >= t && dp[s - t]) cnt[t]++;
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2260 KB Output is correct
2 Correct 9 ms 2316 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 7 ms 2320 KB Output is correct
5 Correct 16 ms 2260 KB Output is correct
6 Correct 12 ms 2260 KB Output is correct
7 Correct 9 ms 2260 KB Output is correct
8 Correct 16 ms 2260 KB Output is correct
9 Correct 13 ms 2248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2260 KB Output is correct
2 Correct 9 ms 2316 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 7 ms 2320 KB Output is correct
5 Correct 16 ms 2260 KB Output is correct
6 Correct 12 ms 2260 KB Output is correct
7 Correct 9 ms 2260 KB Output is correct
8 Correct 16 ms 2260 KB Output is correct
9 Correct 13 ms 2248 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 40 ms 2216 KB Output is correct
12 Correct 39 ms 2220 KB Output is correct
13 Correct 34 ms 2300 KB Output is correct
14 Correct 36 ms 2240 KB Output is correct
15 Correct 38 ms 2260 KB Output is correct
16 Correct 41 ms 2300 KB Output is correct
17 Correct 24 ms 2260 KB Output is correct
18 Correct 32 ms 2260 KB Output is correct
19 Correct 34 ms 2260 KB Output is correct
20 Correct 39 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2260 KB Output is correct
2 Correct 9 ms 2316 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 7 ms 2320 KB Output is correct
5 Correct 16 ms 2260 KB Output is correct
6 Correct 12 ms 2260 KB Output is correct
7 Correct 9 ms 2260 KB Output is correct
8 Correct 16 ms 2260 KB Output is correct
9 Correct 13 ms 2248 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 40 ms 2216 KB Output is correct
12 Correct 39 ms 2220 KB Output is correct
13 Correct 34 ms 2300 KB Output is correct
14 Correct 36 ms 2240 KB Output is correct
15 Correct 38 ms 2260 KB Output is correct
16 Correct 41 ms 2300 KB Output is correct
17 Correct 24 ms 2260 KB Output is correct
18 Correct 32 ms 2260 KB Output is correct
19 Correct 34 ms 2260 KB Output is correct
20 Correct 39 ms 2296 KB Output is correct
21 Correct 81 ms 2304 KB Output is correct
22 Correct 92 ms 2300 KB Output is correct
23 Correct 69 ms 2252 KB Output is correct
24 Correct 122 ms 2300 KB Output is correct
25 Correct 116 ms 2220 KB Output is correct
26 Correct 129 ms 2300 KB Output is correct
27 Correct 129 ms 2332 KB Output is correct
28 Correct 126 ms 2336 KB Output is correct
29 Correct 132 ms 2300 KB Output is correct
30 Correct 143 ms 2296 KB Output is correct
31 Correct 125 ms 2200 KB Output is correct
32 Correct 126 ms 2296 KB Output is correct
33 Correct 125 ms 2312 KB Output is correct
34 Correct 127 ms 2200 KB Output is correct
35 Correct 122 ms 2220 KB Output is correct
36 Correct 127 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2260 KB Output is correct
2 Correct 9 ms 2316 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 7 ms 2320 KB Output is correct
5 Correct 16 ms 2260 KB Output is correct
6 Correct 12 ms 2260 KB Output is correct
7 Correct 9 ms 2260 KB Output is correct
8 Correct 16 ms 2260 KB Output is correct
9 Correct 13 ms 2248 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 40 ms 2216 KB Output is correct
12 Correct 39 ms 2220 KB Output is correct
13 Correct 34 ms 2300 KB Output is correct
14 Correct 36 ms 2240 KB Output is correct
15 Correct 38 ms 2260 KB Output is correct
16 Correct 41 ms 2300 KB Output is correct
17 Correct 24 ms 2260 KB Output is correct
18 Correct 32 ms 2260 KB Output is correct
19 Correct 34 ms 2260 KB Output is correct
20 Correct 39 ms 2296 KB Output is correct
21 Correct 81 ms 2304 KB Output is correct
22 Correct 92 ms 2300 KB Output is correct
23 Correct 69 ms 2252 KB Output is correct
24 Correct 122 ms 2300 KB Output is correct
25 Correct 116 ms 2220 KB Output is correct
26 Correct 129 ms 2300 KB Output is correct
27 Correct 129 ms 2332 KB Output is correct
28 Correct 126 ms 2336 KB Output is correct
29 Correct 132 ms 2300 KB Output is correct
30 Correct 143 ms 2296 KB Output is correct
31 Correct 125 ms 2200 KB Output is correct
32 Correct 126 ms 2296 KB Output is correct
33 Correct 125 ms 2312 KB Output is correct
34 Correct 127 ms 2200 KB Output is correct
35 Correct 122 ms 2220 KB Output is correct
36 Correct 127 ms 2300 KB Output is correct
37 Correct 258 ms 2328 KB Output is correct
38 Correct 259 ms 2336 KB Output is correct
39 Correct 315 ms 2336 KB Output is correct
40 Correct 336 ms 2304 KB Output is correct
41 Correct 344 ms 2348 KB Output is correct
42 Correct 320 ms 2332 KB Output is correct
43 Correct 296 ms 2332 KB Output is correct
44 Correct 313 ms 2432 KB Output is correct
45 Correct 308 ms 2428 KB Output is correct
46 Correct 355 ms 2300 KB Output is correct
47 Correct 312 ms 2300 KB Output is correct
48 Correct 314 ms 2300 KB Output is correct
49 Correct 309 ms 2296 KB Output is correct
50 Correct 309 ms 2344 KB Output is correct
51 Correct 87 ms 1236 KB Output is correct
52 Correct 336 ms 2460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2260 KB Output is correct
2 Correct 9 ms 2316 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 7 ms 2320 KB Output is correct
5 Correct 16 ms 2260 KB Output is correct
6 Correct 12 ms 2260 KB Output is correct
7 Correct 9 ms 2260 KB Output is correct
8 Correct 16 ms 2260 KB Output is correct
9 Correct 13 ms 2248 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 40 ms 2216 KB Output is correct
12 Correct 39 ms 2220 KB Output is correct
13 Correct 34 ms 2300 KB Output is correct
14 Correct 36 ms 2240 KB Output is correct
15 Correct 38 ms 2260 KB Output is correct
16 Correct 41 ms 2300 KB Output is correct
17 Correct 24 ms 2260 KB Output is correct
18 Correct 32 ms 2260 KB Output is correct
19 Correct 34 ms 2260 KB Output is correct
20 Correct 39 ms 2296 KB Output is correct
21 Correct 81 ms 2304 KB Output is correct
22 Correct 92 ms 2300 KB Output is correct
23 Correct 69 ms 2252 KB Output is correct
24 Correct 122 ms 2300 KB Output is correct
25 Correct 116 ms 2220 KB Output is correct
26 Correct 129 ms 2300 KB Output is correct
27 Correct 129 ms 2332 KB Output is correct
28 Correct 126 ms 2336 KB Output is correct
29 Correct 132 ms 2300 KB Output is correct
30 Correct 143 ms 2296 KB Output is correct
31 Correct 125 ms 2200 KB Output is correct
32 Correct 126 ms 2296 KB Output is correct
33 Correct 125 ms 2312 KB Output is correct
34 Correct 127 ms 2200 KB Output is correct
35 Correct 122 ms 2220 KB Output is correct
36 Correct 127 ms 2300 KB Output is correct
37 Correct 258 ms 2328 KB Output is correct
38 Correct 259 ms 2336 KB Output is correct
39 Correct 315 ms 2336 KB Output is correct
40 Correct 336 ms 2304 KB Output is correct
41 Correct 344 ms 2348 KB Output is correct
42 Correct 320 ms 2332 KB Output is correct
43 Correct 296 ms 2332 KB Output is correct
44 Correct 313 ms 2432 KB Output is correct
45 Correct 308 ms 2428 KB Output is correct
46 Correct 355 ms 2300 KB Output is correct
47 Correct 312 ms 2300 KB Output is correct
48 Correct 314 ms 2300 KB Output is correct
49 Correct 309 ms 2296 KB Output is correct
50 Correct 309 ms 2344 KB Output is correct
51 Correct 87 ms 1236 KB Output is correct
52 Correct 336 ms 2460 KB Output is correct
53 Correct 384 ms 2428 KB Output is correct
54 Correct 430 ms 2348 KB Output is correct
55 Correct 440 ms 2556 KB Output is correct
56 Correct 382 ms 2460 KB Output is correct
57 Correct 452 ms 2588 KB Output is correct
58 Correct 454 ms 2508 KB Output is correct
59 Correct 420 ms 2508 KB Output is correct
60 Correct 118 ms 1312 KB Output is correct
61 Correct 435 ms 2460 KB Output is correct
62 Correct 399 ms 2556 KB Output is correct
63 Correct 396 ms 2588 KB Output is correct
64 Correct 386 ms 2552 KB Output is correct
65 Correct 397 ms 2300 KB Output is correct
66 Correct 381 ms 2340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2260 KB Output is correct
2 Correct 9 ms 2316 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 7 ms 2320 KB Output is correct
5 Correct 16 ms 2260 KB Output is correct
6 Correct 12 ms 2260 KB Output is correct
7 Correct 9 ms 2260 KB Output is correct
8 Correct 16 ms 2260 KB Output is correct
9 Correct 13 ms 2248 KB Output is correct
10 Correct 45 ms 2260 KB Output is correct
11 Correct 40 ms 2216 KB Output is correct
12 Correct 39 ms 2220 KB Output is correct
13 Correct 34 ms 2300 KB Output is correct
14 Correct 36 ms 2240 KB Output is correct
15 Correct 38 ms 2260 KB Output is correct
16 Correct 41 ms 2300 KB Output is correct
17 Correct 24 ms 2260 KB Output is correct
18 Correct 32 ms 2260 KB Output is correct
19 Correct 34 ms 2260 KB Output is correct
20 Correct 39 ms 2296 KB Output is correct
21 Correct 81 ms 2304 KB Output is correct
22 Correct 92 ms 2300 KB Output is correct
23 Correct 69 ms 2252 KB Output is correct
24 Correct 122 ms 2300 KB Output is correct
25 Correct 116 ms 2220 KB Output is correct
26 Correct 129 ms 2300 KB Output is correct
27 Correct 129 ms 2332 KB Output is correct
28 Correct 126 ms 2336 KB Output is correct
29 Correct 132 ms 2300 KB Output is correct
30 Correct 143 ms 2296 KB Output is correct
31 Correct 125 ms 2200 KB Output is correct
32 Correct 126 ms 2296 KB Output is correct
33 Correct 125 ms 2312 KB Output is correct
34 Correct 127 ms 2200 KB Output is correct
35 Correct 122 ms 2220 KB Output is correct
36 Correct 127 ms 2300 KB Output is correct
37 Correct 258 ms 2328 KB Output is correct
38 Correct 259 ms 2336 KB Output is correct
39 Correct 315 ms 2336 KB Output is correct
40 Correct 336 ms 2304 KB Output is correct
41 Correct 344 ms 2348 KB Output is correct
42 Correct 320 ms 2332 KB Output is correct
43 Correct 296 ms 2332 KB Output is correct
44 Correct 313 ms 2432 KB Output is correct
45 Correct 308 ms 2428 KB Output is correct
46 Correct 355 ms 2300 KB Output is correct
47 Correct 312 ms 2300 KB Output is correct
48 Correct 314 ms 2300 KB Output is correct
49 Correct 309 ms 2296 KB Output is correct
50 Correct 309 ms 2344 KB Output is correct
51 Correct 87 ms 1236 KB Output is correct
52 Correct 336 ms 2460 KB Output is correct
53 Correct 384 ms 2428 KB Output is correct
54 Correct 430 ms 2348 KB Output is correct
55 Correct 440 ms 2556 KB Output is correct
56 Correct 382 ms 2460 KB Output is correct
57 Correct 452 ms 2588 KB Output is correct
58 Correct 454 ms 2508 KB Output is correct
59 Correct 420 ms 2508 KB Output is correct
60 Correct 118 ms 1312 KB Output is correct
61 Correct 435 ms 2460 KB Output is correct
62 Correct 399 ms 2556 KB Output is correct
63 Correct 396 ms 2588 KB Output is correct
64 Correct 386 ms 2552 KB Output is correct
65 Correct 397 ms 2300 KB Output is correct
66 Correct 381 ms 2340 KB Output is correct
67 Correct 504 ms 2428 KB Output is correct
68 Correct 173 ms 1308 KB Output is correct
69 Correct 631 ms 2940 KB Output is correct
70 Correct 628 ms 2728 KB Output is correct
71 Correct 635 ms 2684 KB Output is correct
72 Correct 637 ms 2296 KB Output is correct
73 Correct 628 ms 2308 KB Output is correct
74 Correct 623 ms 2940 KB Output is correct
75 Correct 632 ms 2844 KB Output is correct
76 Correct 676 ms 2936 KB Output is correct
77 Correct 631 ms 2980 KB Output is correct