Submission #950215

# Submission time Handle Problem Language Result Execution time Memory
950215 2024-03-20T06:57:27 Z Pragmatism Bootfall (IZhO17_bootfall) C++17
100 / 100
312 ms 4052 KB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 5e2 + 7;
const int W = 3e5 + 7;
const int maxA = 1e5 + 7;
const int inf = 1e9 + 7;
const ll INF = 2e18 + 7;
const int MOD = 998244353;
const ld eps = 1e-9;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start = clock();

//#define int long long

int n, a[N], dp[W];
void add(int x) {
    for (int w = W - 1;w >= 0;w--) {
        if (w + x < W)dp[w + x] += dp[w];
    }
    dp[x]++;
}
void del(int x) {
    dp[x]--;
    for (int w = x;w < W;w++)dp[w] -= dp[w - x];
}
bool check(int Tima) {
    for (int w = 0;w < W;w++)dp[w] = 0;
    int sum = 0;
    for (int i = 1;i <= n;i++)add(a[i]), sum += a[i];
    if (sum % 2 == 1 || !dp[sum / 2])return 0;
    add(Tima), sum += Tima;
    for (int i = 1;i <= n;i++) {
        sum -= a[i], del(a[i]);
        if (sum % 2 == 1 || !dp[sum / 2])return 0;
        sum += a[i], add(a[i]);
    }
    return 1;
}
int cnt[W];
void solve() {
    cin >> n;
    for (int i = 1;i <= n;i++)cin >> a[i];
    for (int i = 1;i <= n;i++) {
        if (a[i] % 2 != a[1] % 2)cout << 0, exit(0);
    }
    for (int w = 0;w < W;w++)dp[w] = 0;
    int sum = 0;
    for (int i = 1;i <= n;i++)add(a[i]), sum += a[i];
    if (sum % 2 != 0 || dp[sum / 2] == 0)cout << 0, exit(0);
    for (int i = 1;i <= n;i++) {
        sum -= a[i], del(a[i]);
        for (int w = 1;w < W;w++) {
            if ((w + sum) % 2 != 0)skip;
            if ((sum + w) / 2 - w < 0)skip;
            if (dp[(sum + w) / 2 - w] || (sum + w) / 2 - w == 0)cnt[w]++;
        }
        sum += a[i], add(a[i]);
    }
    vector <int> ans;
    for (int w = 1;w < W;w++) {
        if (cnt[w] == n)ans.pb(w);
    }
    cout << sz(ans) << '\n';
    for (auto w : ans)cout << w << ' ';
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("subsequence.in", "r", stdin);
    //freopen("subsequence.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int t = 1;t <= test;t++) {
        //cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

Compilation message

bootfall.cpp:4: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    4 | #pragma comment(linker, "/stack:200000000")
      |
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2396 KB Output is correct
2 Correct 5 ms 2632 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 8 ms 2396 KB Output is correct
6 Correct 7 ms 2396 KB Output is correct
7 Correct 5 ms 2516 KB Output is correct
8 Correct 7 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2396 KB Output is correct
2 Correct 5 ms 2632 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 8 ms 2396 KB Output is correct
6 Correct 7 ms 2396 KB Output is correct
7 Correct 5 ms 2516 KB Output is correct
8 Correct 7 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 18 ms 2396 KB Output is correct
11 Correct 21 ms 2396 KB Output is correct
12 Correct 19 ms 2636 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 18 ms 2392 KB Output is correct
15 Correct 20 ms 2392 KB Output is correct
16 Correct 21 ms 2396 KB Output is correct
17 Correct 13 ms 2652 KB Output is correct
18 Correct 16 ms 2396 KB Output is correct
19 Correct 18 ms 2640 KB Output is correct
20 Correct 16 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2396 KB Output is correct
2 Correct 5 ms 2632 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 8 ms 2396 KB Output is correct
6 Correct 7 ms 2396 KB Output is correct
7 Correct 5 ms 2516 KB Output is correct
8 Correct 7 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 18 ms 2396 KB Output is correct
11 Correct 21 ms 2396 KB Output is correct
12 Correct 19 ms 2636 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 18 ms 2392 KB Output is correct
15 Correct 20 ms 2392 KB Output is correct
16 Correct 21 ms 2396 KB Output is correct
17 Correct 13 ms 2652 KB Output is correct
18 Correct 16 ms 2396 KB Output is correct
19 Correct 18 ms 2640 KB Output is correct
20 Correct 16 ms 2392 KB Output is correct
21 Correct 32 ms 2512 KB Output is correct
22 Correct 39 ms 2644 KB Output is correct
23 Correct 27 ms 2648 KB Output is correct
24 Correct 53 ms 2636 KB Output is correct
25 Correct 50 ms 2636 KB Output is correct
26 Correct 58 ms 2652 KB Output is correct
27 Correct 47 ms 2660 KB Output is correct
28 Correct 47 ms 2660 KB Output is correct
29 Correct 53 ms 2632 KB Output is correct
30 Correct 0 ms 600 KB Output is correct
31 Correct 49 ms 2652 KB Output is correct
32 Correct 52 ms 2652 KB Output is correct
33 Correct 51 ms 2648 KB Output is correct
34 Correct 48 ms 2652 KB Output is correct
35 Correct 58 ms 2652 KB Output is correct
36 Correct 57 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2396 KB Output is correct
2 Correct 5 ms 2632 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 8 ms 2396 KB Output is correct
6 Correct 7 ms 2396 KB Output is correct
7 Correct 5 ms 2516 KB Output is correct
8 Correct 7 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 18 ms 2396 KB Output is correct
11 Correct 21 ms 2396 KB Output is correct
12 Correct 19 ms 2636 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 18 ms 2392 KB Output is correct
15 Correct 20 ms 2392 KB Output is correct
16 Correct 21 ms 2396 KB Output is correct
17 Correct 13 ms 2652 KB Output is correct
18 Correct 16 ms 2396 KB Output is correct
19 Correct 18 ms 2640 KB Output is correct
20 Correct 16 ms 2392 KB Output is correct
21 Correct 32 ms 2512 KB Output is correct
22 Correct 39 ms 2644 KB Output is correct
23 Correct 27 ms 2648 KB Output is correct
24 Correct 53 ms 2636 KB Output is correct
25 Correct 50 ms 2636 KB Output is correct
26 Correct 58 ms 2652 KB Output is correct
27 Correct 47 ms 2660 KB Output is correct
28 Correct 47 ms 2660 KB Output is correct
29 Correct 53 ms 2632 KB Output is correct
30 Correct 0 ms 600 KB Output is correct
31 Correct 49 ms 2652 KB Output is correct
32 Correct 52 ms 2652 KB Output is correct
33 Correct 51 ms 2648 KB Output is correct
34 Correct 48 ms 2652 KB Output is correct
35 Correct 58 ms 2652 KB Output is correct
36 Correct 57 ms 2640 KB Output is correct
37 Correct 103 ms 2644 KB Output is correct
38 Correct 96 ms 2684 KB Output is correct
39 Correct 112 ms 2896 KB Output is correct
40 Correct 162 ms 3120 KB Output is correct
41 Correct 140 ms 2792 KB Output is correct
42 Correct 124 ms 2900 KB Output is correct
43 Correct 136 ms 3124 KB Output is correct
44 Correct 151 ms 3152 KB Output is correct
45 Correct 134 ms 3048 KB Output is correct
46 Correct 134 ms 2644 KB Output is correct
47 Correct 124 ms 2736 KB Output is correct
48 Correct 143 ms 3044 KB Output is correct
49 Correct 150 ms 2792 KB Output is correct
50 Correct 129 ms 2744 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 158 ms 3044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2396 KB Output is correct
2 Correct 5 ms 2632 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 8 ms 2396 KB Output is correct
6 Correct 7 ms 2396 KB Output is correct
7 Correct 5 ms 2516 KB Output is correct
8 Correct 7 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 18 ms 2396 KB Output is correct
11 Correct 21 ms 2396 KB Output is correct
12 Correct 19 ms 2636 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 18 ms 2392 KB Output is correct
15 Correct 20 ms 2392 KB Output is correct
16 Correct 21 ms 2396 KB Output is correct
17 Correct 13 ms 2652 KB Output is correct
18 Correct 16 ms 2396 KB Output is correct
19 Correct 18 ms 2640 KB Output is correct
20 Correct 16 ms 2392 KB Output is correct
21 Correct 32 ms 2512 KB Output is correct
22 Correct 39 ms 2644 KB Output is correct
23 Correct 27 ms 2648 KB Output is correct
24 Correct 53 ms 2636 KB Output is correct
25 Correct 50 ms 2636 KB Output is correct
26 Correct 58 ms 2652 KB Output is correct
27 Correct 47 ms 2660 KB Output is correct
28 Correct 47 ms 2660 KB Output is correct
29 Correct 53 ms 2632 KB Output is correct
30 Correct 0 ms 600 KB Output is correct
31 Correct 49 ms 2652 KB Output is correct
32 Correct 52 ms 2652 KB Output is correct
33 Correct 51 ms 2648 KB Output is correct
34 Correct 48 ms 2652 KB Output is correct
35 Correct 58 ms 2652 KB Output is correct
36 Correct 57 ms 2640 KB Output is correct
37 Correct 103 ms 2644 KB Output is correct
38 Correct 96 ms 2684 KB Output is correct
39 Correct 112 ms 2896 KB Output is correct
40 Correct 162 ms 3120 KB Output is correct
41 Correct 140 ms 2792 KB Output is correct
42 Correct 124 ms 2900 KB Output is correct
43 Correct 136 ms 3124 KB Output is correct
44 Correct 151 ms 3152 KB Output is correct
45 Correct 134 ms 3048 KB Output is correct
46 Correct 134 ms 2644 KB Output is correct
47 Correct 124 ms 2736 KB Output is correct
48 Correct 143 ms 3044 KB Output is correct
49 Correct 150 ms 2792 KB Output is correct
50 Correct 129 ms 2744 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 158 ms 3044 KB Output is correct
53 Correct 173 ms 3036 KB Output is correct
54 Correct 173 ms 3040 KB Output is correct
55 Correct 197 ms 3264 KB Output is correct
56 Correct 172 ms 3040 KB Output is correct
57 Correct 177 ms 3432 KB Output is correct
58 Correct 214 ms 3044 KB Output is correct
59 Correct 178 ms 3172 KB Output is correct
60 Correct 0 ms 464 KB Output is correct
61 Correct 178 ms 3256 KB Output is correct
62 Correct 190 ms 3172 KB Output is correct
63 Correct 163 ms 3280 KB Output is correct
64 Correct 146 ms 3288 KB Output is correct
65 Correct 191 ms 2672 KB Output is correct
66 Correct 165 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2396 KB Output is correct
2 Correct 5 ms 2632 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 8 ms 2396 KB Output is correct
6 Correct 7 ms 2396 KB Output is correct
7 Correct 5 ms 2516 KB Output is correct
8 Correct 7 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 18 ms 2396 KB Output is correct
11 Correct 21 ms 2396 KB Output is correct
12 Correct 19 ms 2636 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 18 ms 2392 KB Output is correct
15 Correct 20 ms 2392 KB Output is correct
16 Correct 21 ms 2396 KB Output is correct
17 Correct 13 ms 2652 KB Output is correct
18 Correct 16 ms 2396 KB Output is correct
19 Correct 18 ms 2640 KB Output is correct
20 Correct 16 ms 2392 KB Output is correct
21 Correct 32 ms 2512 KB Output is correct
22 Correct 39 ms 2644 KB Output is correct
23 Correct 27 ms 2648 KB Output is correct
24 Correct 53 ms 2636 KB Output is correct
25 Correct 50 ms 2636 KB Output is correct
26 Correct 58 ms 2652 KB Output is correct
27 Correct 47 ms 2660 KB Output is correct
28 Correct 47 ms 2660 KB Output is correct
29 Correct 53 ms 2632 KB Output is correct
30 Correct 0 ms 600 KB Output is correct
31 Correct 49 ms 2652 KB Output is correct
32 Correct 52 ms 2652 KB Output is correct
33 Correct 51 ms 2648 KB Output is correct
34 Correct 48 ms 2652 KB Output is correct
35 Correct 58 ms 2652 KB Output is correct
36 Correct 57 ms 2640 KB Output is correct
37 Correct 103 ms 2644 KB Output is correct
38 Correct 96 ms 2684 KB Output is correct
39 Correct 112 ms 2896 KB Output is correct
40 Correct 162 ms 3120 KB Output is correct
41 Correct 140 ms 2792 KB Output is correct
42 Correct 124 ms 2900 KB Output is correct
43 Correct 136 ms 3124 KB Output is correct
44 Correct 151 ms 3152 KB Output is correct
45 Correct 134 ms 3048 KB Output is correct
46 Correct 134 ms 2644 KB Output is correct
47 Correct 124 ms 2736 KB Output is correct
48 Correct 143 ms 3044 KB Output is correct
49 Correct 150 ms 2792 KB Output is correct
50 Correct 129 ms 2744 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 158 ms 3044 KB Output is correct
53 Correct 173 ms 3036 KB Output is correct
54 Correct 173 ms 3040 KB Output is correct
55 Correct 197 ms 3264 KB Output is correct
56 Correct 172 ms 3040 KB Output is correct
57 Correct 177 ms 3432 KB Output is correct
58 Correct 214 ms 3044 KB Output is correct
59 Correct 178 ms 3172 KB Output is correct
60 Correct 0 ms 464 KB Output is correct
61 Correct 178 ms 3256 KB Output is correct
62 Correct 190 ms 3172 KB Output is correct
63 Correct 163 ms 3280 KB Output is correct
64 Correct 146 ms 3288 KB Output is correct
65 Correct 191 ms 2672 KB Output is correct
66 Correct 165 ms 2644 KB Output is correct
67 Correct 205 ms 3288 KB Output is correct
68 Correct 80 ms 2512 KB Output is correct
69 Correct 312 ms 3936 KB Output is correct
70 Correct 274 ms 3544 KB Output is correct
71 Correct 252 ms 3432 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 272 ms 4052 KB Output is correct
75 Correct 289 ms 3684 KB Output is correct
76 Correct 276 ms 3940 KB Output is correct
77 Correct 263 ms 4032 KB Output is correct