Submission #1110865

# Submission time Handle Problem Language Result Execution time Memory
1110865 2024-11-10T16:43:40 Z anmattroi Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
557 ms 46408 KB
#include <bits/stdc++.h>

using namespace std;

int L, q;
int a[1<<20], Dp_sub[1<<20], Dp_par[1<<20], dem[1<<20];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);



    cin >> L >> q;
    for (int i = 0; i < (1<<L); i++) {
        char c; cin >> c;
        a[i] = Dp_sub[i] = Dp_par[i] = c-'0';
        dem[i] = __builtin_popcount(i);
    }

    for (int i = 0; i < L; i++) {
        for (int mask = 0; mask < (1<<L); ++mask) {
            if ((mask>>i)&1) Dp_sub[mask] += Dp_sub[mask^(1<<i)];
            else Dp_par[mask] += Dp_par[mask^(1<<i)];
        }
    }

    auto sub1 = [&](const string &s) -> void {
        int mask = 0, Smask = 0;
        for (int i = 0; i < L; i++) {
            if (s[i] != '?') mask |= ((s[i]-'0') << i);
            else Smask |= (1<<i);
        }
        int ans = a[mask];
        for (int i = Smask; i > 0; i = (i-1)&Smask) ans += a[i^mask];
        cout << ans << "\n";
    };

    auto sub2 = [&](const string &s) -> void {
        int mask = 0, Smask = 0;
        for (int i = 0; i < L; i++) {
            if (s[i] == '1') {
                Smask |= (1<<i);
                mask |= (1<<i);
            } else if (s[i] == '?') mask |= (1<<i);
        }
        int ans = Dp_sub[mask];

        for (int i = Smask; i > 0; i = (i-1)&Smask) {
            if (dem[i]&1) ans -= Dp_sub[mask^i];
            else ans += Dp_sub[mask^i];
        }
        cout << ans << "\n";
    };

    auto sub3 = [&](const string &s) -> void {
        int mask = 0, Smask = 0;
        for (int i = 0; i < L; i++) {
            if (s[i] == '0') Smask |= (1<<i);
            else if (s[i] == '1') mask |= (1<<i);
        }
        int ans = Dp_par[mask];

        for (int i = Smask; i > 0; i = (i-1)&Smask) {
            if (dem[i]&1) ans -= Dp_par[mask^i];
            else ans += Dp_par[mask^i];
        }
        cout << ans << "\n";
    };

    while (q--) {
        string s; cin >> s;
        reverse(s.begin(), s.end());
        int cnt0 = 0, cnt1 = 0, cnt2 = 0;
        for (char ch : s) {
            switch (ch) {
                case '0' :
                    ++cnt0;
                    break;
                case '1' :
                    ++cnt1;
                    break;
                case '?' :
                    ++cnt2;
                    break;
                }
        }
        if (cnt2 <= 6) sub1(s);
        else if (cnt1 <= 6) sub2(s);
        else sub3(s);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6648 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6648 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 187 ms 21320 KB Output is correct
12 Correct 184 ms 20988 KB Output is correct
13 Correct 192 ms 20040 KB Output is correct
14 Correct 166 ms 20296 KB Output is correct
15 Correct 204 ms 21320 KB Output is correct
16 Correct 189 ms 20552 KB Output is correct
17 Correct 190 ms 20296 KB Output is correct
18 Correct 132 ms 22344 KB Output is correct
19 Correct 151 ms 19272 KB Output is correct
20 Correct 201 ms 20808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6648 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 187 ms 21320 KB Output is correct
12 Correct 184 ms 20988 KB Output is correct
13 Correct 192 ms 20040 KB Output is correct
14 Correct 166 ms 20296 KB Output is correct
15 Correct 204 ms 21320 KB Output is correct
16 Correct 189 ms 20552 KB Output is correct
17 Correct 190 ms 20296 KB Output is correct
18 Correct 132 ms 22344 KB Output is correct
19 Correct 151 ms 19272 KB Output is correct
20 Correct 201 ms 20808 KB Output is correct
21 Correct 285 ms 24136 KB Output is correct
22 Correct 196 ms 24392 KB Output is correct
23 Correct 213 ms 23368 KB Output is correct
24 Correct 219 ms 23112 KB Output is correct
25 Correct 184 ms 25160 KB Output is correct
26 Correct 242 ms 23624 KB Output is correct
27 Correct 241 ms 23880 KB Output is correct
28 Correct 152 ms 26152 KB Output is correct
29 Correct 208 ms 22420 KB Output is correct
30 Correct 283 ms 24392 KB Output is correct
31 Correct 286 ms 24280 KB Output is correct
32 Correct 226 ms 24324 KB Output is correct
33 Correct 218 ms 23112 KB Output is correct
34 Correct 215 ms 23112 KB Output is correct
35 Correct 243 ms 23624 KB Output is correct
36 Correct 123 ms 22088 KB Output is correct
37 Correct 227 ms 24136 KB Output is correct
38 Correct 188 ms 22128 KB Output is correct
39 Correct 229 ms 23456 KB Output is correct
40 Correct 203 ms 23112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6648 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 42 ms 19184 KB Output is correct
12 Correct 43 ms 19156 KB Output is correct
13 Correct 46 ms 19088 KB Output is correct
14 Correct 52 ms 18904 KB Output is correct
15 Correct 45 ms 19084 KB Output is correct
16 Correct 58 ms 19016 KB Output is correct
17 Correct 49 ms 18904 KB Output is correct
18 Correct 40 ms 19156 KB Output is correct
19 Correct 44 ms 19024 KB Output is correct
20 Correct 45 ms 19156 KB Output is correct
21 Correct 48 ms 19016 KB Output is correct
22 Correct 52 ms 18900 KB Output is correct
23 Correct 45 ms 18904 KB Output is correct
24 Correct 50 ms 19016 KB Output is correct
25 Correct 52 ms 19016 KB Output is correct
26 Correct 41 ms 18760 KB Output is correct
27 Correct 41 ms 19016 KB Output is correct
28 Correct 49 ms 19016 KB Output is correct
29 Correct 48 ms 19020 KB Output is correct
30 Correct 53 ms 19080 KB Output is correct
31 Correct 44 ms 19016 KB Output is correct
32 Correct 58 ms 19016 KB Output is correct
33 Correct 55 ms 19016 KB Output is correct
34 Correct 47 ms 18896 KB Output is correct
35 Correct 51 ms 19068 KB Output is correct
36 Correct 48 ms 19016 KB Output is correct
37 Correct 52 ms 18896 KB Output is correct
38 Correct 53 ms 18900 KB Output is correct
39 Correct 61 ms 18896 KB Output is correct
40 Correct 55 ms 19016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6648 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 187 ms 21320 KB Output is correct
12 Correct 184 ms 20988 KB Output is correct
13 Correct 192 ms 20040 KB Output is correct
14 Correct 166 ms 20296 KB Output is correct
15 Correct 204 ms 21320 KB Output is correct
16 Correct 189 ms 20552 KB Output is correct
17 Correct 190 ms 20296 KB Output is correct
18 Correct 132 ms 22344 KB Output is correct
19 Correct 151 ms 19272 KB Output is correct
20 Correct 201 ms 20808 KB Output is correct
21 Correct 285 ms 24136 KB Output is correct
22 Correct 196 ms 24392 KB Output is correct
23 Correct 213 ms 23368 KB Output is correct
24 Correct 219 ms 23112 KB Output is correct
25 Correct 184 ms 25160 KB Output is correct
26 Correct 242 ms 23624 KB Output is correct
27 Correct 241 ms 23880 KB Output is correct
28 Correct 152 ms 26152 KB Output is correct
29 Correct 208 ms 22420 KB Output is correct
30 Correct 283 ms 24392 KB Output is correct
31 Correct 286 ms 24280 KB Output is correct
32 Correct 226 ms 24324 KB Output is correct
33 Correct 218 ms 23112 KB Output is correct
34 Correct 215 ms 23112 KB Output is correct
35 Correct 243 ms 23624 KB Output is correct
36 Correct 123 ms 22088 KB Output is correct
37 Correct 227 ms 24136 KB Output is correct
38 Correct 188 ms 22128 KB Output is correct
39 Correct 229 ms 23456 KB Output is correct
40 Correct 203 ms 23112 KB Output is correct
41 Correct 42 ms 19184 KB Output is correct
42 Correct 43 ms 19156 KB Output is correct
43 Correct 46 ms 19088 KB Output is correct
44 Correct 52 ms 18904 KB Output is correct
45 Correct 45 ms 19084 KB Output is correct
46 Correct 58 ms 19016 KB Output is correct
47 Correct 49 ms 18904 KB Output is correct
48 Correct 40 ms 19156 KB Output is correct
49 Correct 44 ms 19024 KB Output is correct
50 Correct 45 ms 19156 KB Output is correct
51 Correct 48 ms 19016 KB Output is correct
52 Correct 52 ms 18900 KB Output is correct
53 Correct 45 ms 18904 KB Output is correct
54 Correct 50 ms 19016 KB Output is correct
55 Correct 52 ms 19016 KB Output is correct
56 Correct 41 ms 18760 KB Output is correct
57 Correct 41 ms 19016 KB Output is correct
58 Correct 49 ms 19016 KB Output is correct
59 Correct 48 ms 19020 KB Output is correct
60 Correct 53 ms 19080 KB Output is correct
61 Correct 44 ms 19016 KB Output is correct
62 Correct 58 ms 19016 KB Output is correct
63 Correct 55 ms 19016 KB Output is correct
64 Correct 47 ms 18896 KB Output is correct
65 Correct 51 ms 19068 KB Output is correct
66 Correct 48 ms 19016 KB Output is correct
67 Correct 52 ms 18896 KB Output is correct
68 Correct 53 ms 18900 KB Output is correct
69 Correct 61 ms 18896 KB Output is correct
70 Correct 55 ms 19016 KB Output is correct
71 Correct 327 ms 43336 KB Output is correct
72 Correct 237 ms 43340 KB Output is correct
73 Correct 424 ms 42056 KB Output is correct
74 Correct 557 ms 42200 KB Output is correct
75 Correct 355 ms 44360 KB Output is correct
76 Correct 512 ms 42624 KB Output is correct
77 Correct 461 ms 42572 KB Output is correct
78 Correct 235 ms 46408 KB Output is correct
79 Correct 286 ms 40264 KB Output is correct
80 Correct 327 ms 43552 KB Output is correct
81 Correct 408 ms 43228 KB Output is correct
82 Correct 532 ms 42368 KB Output is correct
83 Correct 349 ms 41288 KB Output is correct
84 Correct 433 ms 42312 KB Output is correct
85 Correct 403 ms 42568 KB Output is correct
86 Correct 183 ms 40588 KB Output is correct
87 Correct 230 ms 43336 KB Output is correct
88 Correct 297 ms 40012 KB Output is correct
89 Correct 396 ms 42024 KB Output is correct
90 Correct 485 ms 42332 KB Output is correct
91 Correct 331 ms 41544 KB Output is correct
92 Correct 480 ms 42704 KB Output is correct
93 Correct 449 ms 42576 KB Output is correct
94 Correct 206 ms 40400 KB Output is correct
95 Correct 390 ms 42312 KB Output is correct
96 Correct 365 ms 42320 KB Output is correct
97 Correct 392 ms 42312 KB Output is correct
98 Correct 391 ms 42456 KB Output is correct
99 Correct 372 ms 42304 KB Output is correct
100 Correct 387 ms 42312 KB Output is correct