Submission #591016

# Submission time Handle Problem Language Result Execution time Memory
591016 2022-07-06T17:49:44 Z piOOE Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
954 ms 25836 KB
#include <bits/stdc++.h>

using namespace std;

const int L = 20;

int S[1 << L], A[1 << L], B[1 << L], popcnt[1 << L];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    for (int i = 1; i < 1 << L; ++i) {
        popcnt[i] = popcnt[i >> 1] + (i & 1);
    }
    int l, q;
    string s;
    cin >> l >> q >> s;
    int n = 1 << l;
    for (int i = 0; i < n; ++i) {
        S[i] = A[i] = B[(n - 1) ^ i] = s[i] - '0';
    }
    for (int i = 0; i < l; ++i) {
        for (int mask = 0; mask < n; ++mask) {
            if (mask & 1 << i) {
                A[mask] += A[mask ^ 1 << i];
                B[mask] += B[mask ^ 1 << i];
            }
        }
    }
    while (q--) {
        string t;
        cin >> t;
        reverse(t.begin(), t.end());
        int mask0 = 0, mask1 = 0, mask2 = 0;
        for (int i = 0; i < l; ++i) {
            if (t[i] == '0') {
                mask0 ^= 1 << i;
            } else if (t[i] == '1') {
                mask1 ^= 1 << i;
            } else {
                mask2 ^= 1 << i;
            }
        }
        int ans = 0;
        if (popcnt[mask1] <= 6) {
            for (int mask = mask1; mask; mask = (mask - 1) & mask1) {
                ans += A[mask ^ mask2] * (popcnt[mask ^ mask1] & 1 ? -1 : 1);
            }
            ans += A[mask2] * (popcnt[mask1] & 1 ? -1 : 1);
        } else if (popcnt[mask0] <= 6) {
            for (int mask = mask0; mask; mask = (mask - 1) & mask0) {
                ans += B[mask ^ mask2] * (popcnt[mask ^ mask0] & 1 ? -1 : 1);
            }
            ans += B[mask2] * (popcnt[mask0] & 1 ? -1 : 1);
        } else {
            for (int mask = mask2; mask; mask = (mask - 1) & mask2) {
                ans += S[mask ^ mask1];
            }
            ans += S[mask1];
        }
        cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4436 KB Output is correct
2 Correct 4 ms 4436 KB Output is correct
3 Correct 4 ms 4436 KB Output is correct
4 Correct 5 ms 4440 KB Output is correct
5 Correct 3 ms 4436 KB Output is correct
6 Correct 4 ms 4376 KB Output is correct
7 Correct 4 ms 4432 KB Output is correct
8 Correct 4 ms 4436 KB Output is correct
9 Correct 3 ms 4436 KB Output is correct
10 Correct 4 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4436 KB Output is correct
2 Correct 4 ms 4436 KB Output is correct
3 Correct 4 ms 4436 KB Output is correct
4 Correct 5 ms 4440 KB Output is correct
5 Correct 3 ms 4436 KB Output is correct
6 Correct 4 ms 4376 KB Output is correct
7 Correct 4 ms 4432 KB Output is correct
8 Correct 4 ms 4436 KB Output is correct
9 Correct 3 ms 4436 KB Output is correct
10 Correct 4 ms 4436 KB Output is correct
11 Correct 263 ms 8540 KB Output is correct
12 Correct 276 ms 8160 KB Output is correct
13 Correct 238 ms 7500 KB Output is correct
14 Correct 288 ms 7464 KB Output is correct
15 Correct 228 ms 8552 KB Output is correct
16 Correct 285 ms 7672 KB Output is correct
17 Correct 260 ms 7712 KB Output is correct
18 Correct 176 ms 9484 KB Output is correct
19 Correct 246 ms 6612 KB Output is correct
20 Correct 320 ms 8216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4436 KB Output is correct
2 Correct 4 ms 4436 KB Output is correct
3 Correct 4 ms 4436 KB Output is correct
4 Correct 5 ms 4440 KB Output is correct
5 Correct 3 ms 4436 KB Output is correct
6 Correct 4 ms 4376 KB Output is correct
7 Correct 4 ms 4432 KB Output is correct
8 Correct 4 ms 4436 KB Output is correct
9 Correct 3 ms 4436 KB Output is correct
10 Correct 4 ms 4436 KB Output is correct
11 Correct 263 ms 8540 KB Output is correct
12 Correct 276 ms 8160 KB Output is correct
13 Correct 238 ms 7500 KB Output is correct
14 Correct 288 ms 7464 KB Output is correct
15 Correct 228 ms 8552 KB Output is correct
16 Correct 285 ms 7672 KB Output is correct
17 Correct 260 ms 7712 KB Output is correct
18 Correct 176 ms 9484 KB Output is correct
19 Correct 246 ms 6612 KB Output is correct
20 Correct 320 ms 8216 KB Output is correct
21 Correct 364 ms 8688 KB Output is correct
22 Correct 232 ms 8820 KB Output is correct
23 Correct 294 ms 7816 KB Output is correct
24 Correct 279 ms 7684 KB Output is correct
25 Correct 251 ms 9592 KB Output is correct
26 Correct 302 ms 8088 KB Output is correct
27 Correct 357 ms 8056 KB Output is correct
28 Correct 290 ms 10652 KB Output is correct
29 Correct 381 ms 6676 KB Output is correct
30 Correct 299 ms 8936 KB Output is correct
31 Correct 285 ms 8596 KB Output is correct
32 Correct 282 ms 8600 KB Output is correct
33 Correct 297 ms 7524 KB Output is correct
34 Correct 300 ms 7696 KB Output is correct
35 Correct 312 ms 8132 KB Output is correct
36 Correct 180 ms 6500 KB Output is correct
37 Correct 205 ms 8496 KB Output is correct
38 Correct 383 ms 6460 KB Output is correct
39 Correct 357 ms 7696 KB Output is correct
40 Correct 383 ms 7456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4436 KB Output is correct
2 Correct 4 ms 4436 KB Output is correct
3 Correct 4 ms 4436 KB Output is correct
4 Correct 5 ms 4440 KB Output is correct
5 Correct 3 ms 4436 KB Output is correct
6 Correct 4 ms 4376 KB Output is correct
7 Correct 4 ms 4432 KB Output is correct
8 Correct 4 ms 4436 KB Output is correct
9 Correct 3 ms 4436 KB Output is correct
10 Correct 4 ms 4436 KB Output is correct
11 Correct 54 ms 18120 KB Output is correct
12 Correct 70 ms 18128 KB Output is correct
13 Correct 79 ms 18008 KB Output is correct
14 Correct 61 ms 18076 KB Output is correct
15 Correct 48 ms 18168 KB Output is correct
16 Correct 96 ms 18016 KB Output is correct
17 Correct 80 ms 18016 KB Output is correct
18 Correct 46 ms 18272 KB Output is correct
19 Correct 69 ms 18008 KB Output is correct
20 Correct 71 ms 18152 KB Output is correct
21 Correct 61 ms 18016 KB Output is correct
22 Correct 72 ms 17956 KB Output is correct
23 Correct 77 ms 17996 KB Output is correct
24 Correct 86 ms 18016 KB Output is correct
25 Correct 77 ms 17992 KB Output is correct
26 Correct 48 ms 17888 KB Output is correct
27 Correct 50 ms 18020 KB Output is correct
28 Correct 54 ms 17900 KB Output is correct
29 Correct 58 ms 17960 KB Output is correct
30 Correct 64 ms 18008 KB Output is correct
31 Correct 54 ms 18020 KB Output is correct
32 Correct 77 ms 18016 KB Output is correct
33 Correct 75 ms 18008 KB Output is correct
34 Correct 52 ms 17900 KB Output is correct
35 Correct 68 ms 17972 KB Output is correct
36 Correct 64 ms 18000 KB Output is correct
37 Correct 74 ms 18048 KB Output is correct
38 Correct 65 ms 18048 KB Output is correct
39 Correct 80 ms 18060 KB Output is correct
40 Correct 72 ms 18148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4436 KB Output is correct
2 Correct 4 ms 4436 KB Output is correct
3 Correct 4 ms 4436 KB Output is correct
4 Correct 5 ms 4440 KB Output is correct
5 Correct 3 ms 4436 KB Output is correct
6 Correct 4 ms 4376 KB Output is correct
7 Correct 4 ms 4432 KB Output is correct
8 Correct 4 ms 4436 KB Output is correct
9 Correct 3 ms 4436 KB Output is correct
10 Correct 4 ms 4436 KB Output is correct
11 Correct 263 ms 8540 KB Output is correct
12 Correct 276 ms 8160 KB Output is correct
13 Correct 238 ms 7500 KB Output is correct
14 Correct 288 ms 7464 KB Output is correct
15 Correct 228 ms 8552 KB Output is correct
16 Correct 285 ms 7672 KB Output is correct
17 Correct 260 ms 7712 KB Output is correct
18 Correct 176 ms 9484 KB Output is correct
19 Correct 246 ms 6612 KB Output is correct
20 Correct 320 ms 8216 KB Output is correct
21 Correct 364 ms 8688 KB Output is correct
22 Correct 232 ms 8820 KB Output is correct
23 Correct 294 ms 7816 KB Output is correct
24 Correct 279 ms 7684 KB Output is correct
25 Correct 251 ms 9592 KB Output is correct
26 Correct 302 ms 8088 KB Output is correct
27 Correct 357 ms 8056 KB Output is correct
28 Correct 290 ms 10652 KB Output is correct
29 Correct 381 ms 6676 KB Output is correct
30 Correct 299 ms 8936 KB Output is correct
31 Correct 285 ms 8596 KB Output is correct
32 Correct 282 ms 8600 KB Output is correct
33 Correct 297 ms 7524 KB Output is correct
34 Correct 300 ms 7696 KB Output is correct
35 Correct 312 ms 8132 KB Output is correct
36 Correct 180 ms 6500 KB Output is correct
37 Correct 205 ms 8496 KB Output is correct
38 Correct 383 ms 6460 KB Output is correct
39 Correct 357 ms 7696 KB Output is correct
40 Correct 383 ms 7456 KB Output is correct
41 Correct 54 ms 18120 KB Output is correct
42 Correct 70 ms 18128 KB Output is correct
43 Correct 79 ms 18008 KB Output is correct
44 Correct 61 ms 18076 KB Output is correct
45 Correct 48 ms 18168 KB Output is correct
46 Correct 96 ms 18016 KB Output is correct
47 Correct 80 ms 18016 KB Output is correct
48 Correct 46 ms 18272 KB Output is correct
49 Correct 69 ms 18008 KB Output is correct
50 Correct 71 ms 18152 KB Output is correct
51 Correct 61 ms 18016 KB Output is correct
52 Correct 72 ms 17956 KB Output is correct
53 Correct 77 ms 17996 KB Output is correct
54 Correct 86 ms 18016 KB Output is correct
55 Correct 77 ms 17992 KB Output is correct
56 Correct 48 ms 17888 KB Output is correct
57 Correct 50 ms 18020 KB Output is correct
58 Correct 54 ms 17900 KB Output is correct
59 Correct 58 ms 17960 KB Output is correct
60 Correct 64 ms 18008 KB Output is correct
61 Correct 54 ms 18020 KB Output is correct
62 Correct 77 ms 18016 KB Output is correct
63 Correct 75 ms 18008 KB Output is correct
64 Correct 52 ms 17900 KB Output is correct
65 Correct 68 ms 17972 KB Output is correct
66 Correct 64 ms 18000 KB Output is correct
67 Correct 74 ms 18048 KB Output is correct
68 Correct 65 ms 18048 KB Output is correct
69 Correct 80 ms 18060 KB Output is correct
70 Correct 72 ms 18148 KB Output is correct
71 Correct 451 ms 22896 KB Output is correct
72 Correct 377 ms 22932 KB Output is correct
73 Correct 687 ms 21476 KB Output is correct
74 Correct 756 ms 21884 KB Output is correct
75 Correct 456 ms 23948 KB Output is correct
76 Correct 954 ms 22128 KB Output is correct
77 Correct 735 ms 22056 KB Output is correct
78 Correct 258 ms 25836 KB Output is correct
79 Correct 456 ms 19856 KB Output is correct
80 Correct 525 ms 23020 KB Output is correct
81 Correct 579 ms 22812 KB Output is correct
82 Correct 742 ms 21876 KB Output is correct
83 Correct 414 ms 21052 KB Output is correct
84 Correct 779 ms 21796 KB Output is correct
85 Correct 803 ms 22000 KB Output is correct
86 Correct 240 ms 19952 KB Output is correct
87 Correct 351 ms 22916 KB Output is correct
88 Correct 490 ms 19820 KB Output is correct
89 Correct 599 ms 21456 KB Output is correct
90 Correct 548 ms 21876 KB Output is correct
91 Correct 424 ms 21052 KB Output is correct
92 Correct 593 ms 22124 KB Output is correct
93 Correct 728 ms 22076 KB Output is correct
94 Correct 239 ms 19872 KB Output is correct
95 Correct 627 ms 21968 KB Output is correct
96 Correct 653 ms 22056 KB Output is correct
97 Correct 578 ms 21964 KB Output is correct
98 Correct 632 ms 21940 KB Output is correct
99 Correct 660 ms 22048 KB Output is correct
100 Correct 592 ms 21876 KB Output is correct