Submission #625580

# Submission time Handle Problem Language Result Execution time Memory
625580 2022-08-10T15:14:27 Z Do_you_copy Bootfall (IZhO17_bootfall) C++17
100 / 100
215 ms 32900 KB
#include <bits/stdc++.h>
//#define int long long
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 502 + 1;
const int maxB = 250001;
int n;
int a[maxN];
int sum;
bitset <maxB> bit[5000];
int pos[maxN];
void build(int id, int l, int r){
    if (l == r){
        pos[r] = id;
        return;
    }
    int mid = (l + r) / 2;
    bit[id * 2 + 1] = bit[id * 2] = bit[id];
    for (int i = l; i <= mid; ++i){
        bit[id * 2 + 1] =  bit[id * 2 + 1] | (bit[id * 2 + 1] << a[i]);
    }
    for (int i = mid + 1; i <= r; ++i){
        bit[id * 2] = bit[id * 2] | (bit[id * 2] << a[i]);
    }
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
}

void Init(){
    cin >> n;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
        sum += a[i];
    }
    bit[1][0] = 1;
    build(1, 1, n);
    bitset <maxB> S = bit[pos[1]] | (bit[pos[1]] << a[1]);
    if (sum % 2 || !S[sum / 2]){
        cout << 0;
        return;
    }
    vector <int> ans;
    for (int i = 1; i < maxB; ++i){
        bool flag = 0;
        for (int j = 1; j <= n; ++j){
            int cur = sum - a[j] + i;
            int t = cur / 2;
            if (cur % 2 || i > t || (!bit[pos[j]][t] && !bit[pos[j]][t - i])){
                flag = 1;
                break;
            }
        }
        if (!flag) ans.pb(i);
    }
    cout << ans.size() << "\n";
    for (int i: ans) cout << i << ' ';
}

#define debu
#define taskname "test"
signed main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        #ifdef debug
        freopen(taskname".out", "w", stdout);
        #endif
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << 1000 * double(clock()) / CLOCKS_PER_SEC;
        #ifndef debug
        cerr << "\nTime elapsed: " << 1000 * double(clock()) / CLOCKS_PER_SEC << "ms\n";
        #endif
    }
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 1364 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 1364 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 2516 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 3 ms 2516 KB Output is correct
13 Correct 3 ms 2260 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Correct 3 ms 2388 KB Output is correct
16 Correct 3 ms 2516 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 3 ms 2132 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 1364 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 2516 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 3 ms 2516 KB Output is correct
13 Correct 3 ms 2260 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Correct 3 ms 2388 KB Output is correct
16 Correct 3 ms 2516 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 3 ms 2132 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2516 KB Output is correct
21 Correct 7 ms 4692 KB Output is correct
22 Correct 9 ms 5332 KB Output is correct
23 Correct 5 ms 3812 KB Output is correct
24 Correct 9 ms 6612 KB Output is correct
25 Correct 12 ms 6708 KB Output is correct
26 Correct 12 ms 7040 KB Output is correct
27 Correct 12 ms 7068 KB Output is correct
28 Correct 13 ms 6996 KB Output is correct
29 Correct 10 ms 6996 KB Output is correct
30 Correct 11 ms 6996 KB Output is correct
31 Correct 10 ms 7044 KB Output is correct
32 Correct 10 ms 6996 KB Output is correct
33 Correct 9 ms 6996 KB Output is correct
34 Correct 10 ms 6996 KB Output is correct
35 Correct 9 ms 7040 KB Output is correct
36 Correct 11 ms 6996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 1364 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 2516 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 3 ms 2516 KB Output is correct
13 Correct 3 ms 2260 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Correct 3 ms 2388 KB Output is correct
16 Correct 3 ms 2516 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 3 ms 2132 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2516 KB Output is correct
21 Correct 7 ms 4692 KB Output is correct
22 Correct 9 ms 5332 KB Output is correct
23 Correct 5 ms 3812 KB Output is correct
24 Correct 9 ms 6612 KB Output is correct
25 Correct 12 ms 6708 KB Output is correct
26 Correct 12 ms 7040 KB Output is correct
27 Correct 12 ms 7068 KB Output is correct
28 Correct 13 ms 6996 KB Output is correct
29 Correct 10 ms 6996 KB Output is correct
30 Correct 11 ms 6996 KB Output is correct
31 Correct 10 ms 7044 KB Output is correct
32 Correct 10 ms 6996 KB Output is correct
33 Correct 9 ms 6996 KB Output is correct
34 Correct 10 ms 6996 KB Output is correct
35 Correct 9 ms 7040 KB Output is correct
36 Correct 11 ms 6996 KB Output is correct
37 Correct 35 ms 13464 KB Output is correct
38 Correct 34 ms 13432 KB Output is correct
39 Correct 26 ms 16076 KB Output is correct
40 Correct 46 ms 17656 KB Output is correct
41 Correct 28 ms 17520 KB Output is correct
42 Correct 35 ms 16288 KB Output is correct
43 Correct 41 ms 16204 KB Output is correct
44 Correct 42 ms 16396 KB Output is correct
45 Correct 47 ms 16532 KB Output is correct
46 Correct 32 ms 17520 KB Output is correct
47 Correct 38 ms 16372 KB Output is correct
48 Correct 38 ms 16484 KB Output is correct
49 Correct 28 ms 16156 KB Output is correct
50 Correct 36 ms 16344 KB Output is correct
51 Correct 25 ms 16084 KB Output is correct
52 Correct 47 ms 17880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 1364 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 2516 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 3 ms 2516 KB Output is correct
13 Correct 3 ms 2260 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Correct 3 ms 2388 KB Output is correct
16 Correct 3 ms 2516 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 3 ms 2132 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2516 KB Output is correct
21 Correct 7 ms 4692 KB Output is correct
22 Correct 9 ms 5332 KB Output is correct
23 Correct 5 ms 3812 KB Output is correct
24 Correct 9 ms 6612 KB Output is correct
25 Correct 12 ms 6708 KB Output is correct
26 Correct 12 ms 7040 KB Output is correct
27 Correct 12 ms 7068 KB Output is correct
28 Correct 13 ms 6996 KB Output is correct
29 Correct 10 ms 6996 KB Output is correct
30 Correct 11 ms 6996 KB Output is correct
31 Correct 10 ms 7044 KB Output is correct
32 Correct 10 ms 6996 KB Output is correct
33 Correct 9 ms 6996 KB Output is correct
34 Correct 10 ms 6996 KB Output is correct
35 Correct 9 ms 7040 KB Output is correct
36 Correct 11 ms 6996 KB Output is correct
37 Correct 35 ms 13464 KB Output is correct
38 Correct 34 ms 13432 KB Output is correct
39 Correct 26 ms 16076 KB Output is correct
40 Correct 46 ms 17656 KB Output is correct
41 Correct 28 ms 17520 KB Output is correct
42 Correct 35 ms 16288 KB Output is correct
43 Correct 41 ms 16204 KB Output is correct
44 Correct 42 ms 16396 KB Output is correct
45 Correct 47 ms 16532 KB Output is correct
46 Correct 32 ms 17520 KB Output is correct
47 Correct 38 ms 16372 KB Output is correct
48 Correct 38 ms 16484 KB Output is correct
49 Correct 28 ms 16156 KB Output is correct
50 Correct 36 ms 16344 KB Output is correct
51 Correct 25 ms 16084 KB Output is correct
52 Correct 47 ms 17880 KB Output is correct
53 Correct 54 ms 19732 KB Output is correct
54 Correct 63 ms 23076 KB Output is correct
55 Correct 78 ms 23236 KB Output is correct
56 Correct 55 ms 20252 KB Output is correct
57 Correct 83 ms 23408 KB Output is correct
58 Correct 65 ms 23156 KB Output is correct
59 Correct 80 ms 23216 KB Output is correct
60 Correct 37 ms 22664 KB Output is correct
61 Correct 73 ms 23248 KB Output is correct
62 Correct 71 ms 21328 KB Output is correct
63 Correct 75 ms 21408 KB Output is correct
64 Correct 95 ms 20888 KB Output is correct
65 Correct 35 ms 20484 KB Output is correct
66 Correct 39 ms 20204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 1364 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 2516 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 3 ms 2516 KB Output is correct
13 Correct 3 ms 2260 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Correct 3 ms 2388 KB Output is correct
16 Correct 3 ms 2516 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 3 ms 2132 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2516 KB Output is correct
21 Correct 7 ms 4692 KB Output is correct
22 Correct 9 ms 5332 KB Output is correct
23 Correct 5 ms 3812 KB Output is correct
24 Correct 9 ms 6612 KB Output is correct
25 Correct 12 ms 6708 KB Output is correct
26 Correct 12 ms 7040 KB Output is correct
27 Correct 12 ms 7068 KB Output is correct
28 Correct 13 ms 6996 KB Output is correct
29 Correct 10 ms 6996 KB Output is correct
30 Correct 11 ms 6996 KB Output is correct
31 Correct 10 ms 7044 KB Output is correct
32 Correct 10 ms 6996 KB Output is correct
33 Correct 9 ms 6996 KB Output is correct
34 Correct 10 ms 6996 KB Output is correct
35 Correct 9 ms 7040 KB Output is correct
36 Correct 11 ms 6996 KB Output is correct
37 Correct 35 ms 13464 KB Output is correct
38 Correct 34 ms 13432 KB Output is correct
39 Correct 26 ms 16076 KB Output is correct
40 Correct 46 ms 17656 KB Output is correct
41 Correct 28 ms 17520 KB Output is correct
42 Correct 35 ms 16288 KB Output is correct
43 Correct 41 ms 16204 KB Output is correct
44 Correct 42 ms 16396 KB Output is correct
45 Correct 47 ms 16532 KB Output is correct
46 Correct 32 ms 17520 KB Output is correct
47 Correct 38 ms 16372 KB Output is correct
48 Correct 38 ms 16484 KB Output is correct
49 Correct 28 ms 16156 KB Output is correct
50 Correct 36 ms 16344 KB Output is correct
51 Correct 25 ms 16084 KB Output is correct
52 Correct 47 ms 17880 KB Output is correct
53 Correct 54 ms 19732 KB Output is correct
54 Correct 63 ms 23076 KB Output is correct
55 Correct 78 ms 23236 KB Output is correct
56 Correct 55 ms 20252 KB Output is correct
57 Correct 83 ms 23408 KB Output is correct
58 Correct 65 ms 23156 KB Output is correct
59 Correct 80 ms 23216 KB Output is correct
60 Correct 37 ms 22664 KB Output is correct
61 Correct 73 ms 23248 KB Output is correct
62 Correct 71 ms 21328 KB Output is correct
63 Correct 75 ms 21408 KB Output is correct
64 Correct 95 ms 20888 KB Output is correct
65 Correct 35 ms 20484 KB Output is correct
66 Correct 39 ms 20204 KB Output is correct
67 Correct 85 ms 26320 KB Output is correct
68 Correct 58 ms 31452 KB Output is correct
69 Correct 181 ms 32656 KB Output is correct
70 Correct 141 ms 32340 KB Output is correct
71 Correct 145 ms 32332 KB Output is correct
72 Correct 54 ms 31500 KB Output is correct
73 Correct 54 ms 31388 KB Output is correct
74 Correct 199 ms 32668 KB Output is correct
75 Correct 171 ms 32488 KB Output is correct
76 Correct 183 ms 32732 KB Output is correct
77 Correct 215 ms 32900 KB Output is correct