Submission #873701

# Submission time Handle Problem Language Result Execution time Memory
873701 2023-11-15T13:25:40 Z tvladm2009 Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
572 ms 47736 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int L = 21;
const int M = (1 << L) + 7;
const int K = 6;

int m;
int l;
int q;
string s;
int a[M];
int f[M];
int g[M];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> l >> q >> s;
    m = (1 << l);
    for (int i = 0; i < m; ++i) {
        a[i] = s[i] - '0';
    }
    for (int i = 0; i < m; ++i) {
        f[i] = a[i];
        g[i] = a[i];
    }
    for (int j = 0; j < l; ++j) {
        for (int i = 0; i < m; ++i) {
            if ((i >> j) & 1) {
                f[i] += f[i ^ (1 << j)];
                g[i ^ (1 << j)] += g[i];
            }
        }
    }
    while (q--) {
        vector<int> t(3, 0);
        string tt;
        cin >> tt;
        for (int i = l - 1; i >= 0; --i) {
            t[tt[i] == '?' ? 2 : tt[i] - '0'] |= (1 << (l - i - 1));
        }
        if (__builtin_popcount(t[1]) <= K) {
            int ans = 0;
            int ppc = __builtin_popcount(t[1]);
            for (int z = t[1]; ; z = (z - 1) & t[1]) {
                ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * f[t[2] | z];
                if (z == 0) {
                    break;
                }
            }
            cout << ans << "\n";
        } else if (__builtin_popcount(t[0]) <= K) {
            int ans = 0;
            int ppc = __builtin_popcount(t[0]);
            for (int z = t[0]; ; z = (z - 1) & t[0]) {
                ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * g[t[1] ^ t[0] ^ z];
                if (z == 0) {
                    break;
                }
            }
            cout << ans << "\n";
        } else {
            assert(__builtin_popcount(t[2]) <= K);
            int ans = 0;
            for (int z = t[2]; ; z = (z - 1) & t[2]) {
                ans += a[t[1] | z];
                if (z == 0) {
                    break;
                }
            }
            cout << ans << "\n";
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4568 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4568 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 307 ms 19184 KB Output is correct
12 Correct 202 ms 18764 KB Output is correct
13 Correct 210 ms 18188 KB Output is correct
14 Correct 198 ms 18200 KB Output is correct
15 Correct 232 ms 19228 KB Output is correct
16 Correct 240 ms 18436 KB Output is correct
17 Correct 262 ms 18312 KB Output is correct
18 Correct 152 ms 20152 KB Output is correct
19 Correct 261 ms 17236 KB Output is correct
20 Correct 286 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4568 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 307 ms 19184 KB Output is correct
12 Correct 202 ms 18764 KB Output is correct
13 Correct 210 ms 18188 KB Output is correct
14 Correct 198 ms 18200 KB Output is correct
15 Correct 232 ms 19228 KB Output is correct
16 Correct 240 ms 18436 KB Output is correct
17 Correct 262 ms 18312 KB Output is correct
18 Correct 152 ms 20152 KB Output is correct
19 Correct 261 ms 17236 KB Output is correct
20 Correct 286 ms 19028 KB Output is correct
21 Correct 413 ms 22180 KB Output is correct
22 Correct 218 ms 22412 KB Output is correct
23 Correct 252 ms 21424 KB Output is correct
24 Correct 242 ms 21072 KB Output is correct
25 Correct 232 ms 23124 KB Output is correct
26 Correct 289 ms 21676 KB Output is correct
27 Correct 290 ms 21740 KB Output is correct
28 Correct 162 ms 24200 KB Output is correct
29 Correct 379 ms 20276 KB Output is correct
30 Correct 287 ms 22356 KB Output is correct
31 Correct 263 ms 22216 KB Output is correct
32 Correct 255 ms 22100 KB Output is correct
33 Correct 211 ms 21072 KB Output is correct
34 Correct 278 ms 21412 KB Output is correct
35 Correct 284 ms 21624 KB Output is correct
36 Correct 164 ms 20080 KB Output is correct
37 Correct 205 ms 22104 KB Output is correct
38 Correct 304 ms 20304 KB Output is correct
39 Correct 398 ms 21328 KB Output is correct
40 Correct 299 ms 21072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4568 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 36 ms 20472 KB Output is correct
12 Correct 35 ms 20500 KB Output is correct
13 Correct 46 ms 20224 KB Output is correct
14 Correct 46 ms 20208 KB Output is correct
15 Correct 37 ms 20464 KB Output is correct
16 Correct 44 ms 20288 KB Output is correct
17 Correct 45 ms 20212 KB Output is correct
18 Correct 32 ms 20480 KB Output is correct
19 Correct 33 ms 20108 KB Output is correct
20 Correct 35 ms 20480 KB Output is correct
21 Correct 40 ms 20472 KB Output is correct
22 Correct 48 ms 20208 KB Output is correct
23 Correct 39 ms 20236 KB Output is correct
24 Correct 46 ms 20216 KB Output is correct
25 Correct 43 ms 20240 KB Output is correct
26 Correct 39 ms 20208 KB Output is correct
27 Correct 36 ms 20280 KB Output is correct
28 Correct 34 ms 20208 KB Output is correct
29 Correct 41 ms 20280 KB Output is correct
30 Correct 42 ms 20236 KB Output is correct
31 Correct 39 ms 20212 KB Output is correct
32 Correct 52 ms 20400 KB Output is correct
33 Correct 45 ms 20232 KB Output is correct
34 Correct 38 ms 20480 KB Output is correct
35 Correct 41 ms 20208 KB Output is correct
36 Correct 39 ms 20212 KB Output is correct
37 Correct 42 ms 20256 KB Output is correct
38 Correct 60 ms 20240 KB Output is correct
39 Correct 46 ms 20492 KB Output is correct
40 Correct 50 ms 20348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4568 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 307 ms 19184 KB Output is correct
12 Correct 202 ms 18764 KB Output is correct
13 Correct 210 ms 18188 KB Output is correct
14 Correct 198 ms 18200 KB Output is correct
15 Correct 232 ms 19228 KB Output is correct
16 Correct 240 ms 18436 KB Output is correct
17 Correct 262 ms 18312 KB Output is correct
18 Correct 152 ms 20152 KB Output is correct
19 Correct 261 ms 17236 KB Output is correct
20 Correct 286 ms 19028 KB Output is correct
21 Correct 413 ms 22180 KB Output is correct
22 Correct 218 ms 22412 KB Output is correct
23 Correct 252 ms 21424 KB Output is correct
24 Correct 242 ms 21072 KB Output is correct
25 Correct 232 ms 23124 KB Output is correct
26 Correct 289 ms 21676 KB Output is correct
27 Correct 290 ms 21740 KB Output is correct
28 Correct 162 ms 24200 KB Output is correct
29 Correct 379 ms 20276 KB Output is correct
30 Correct 287 ms 22356 KB Output is correct
31 Correct 263 ms 22216 KB Output is correct
32 Correct 255 ms 22100 KB Output is correct
33 Correct 211 ms 21072 KB Output is correct
34 Correct 278 ms 21412 KB Output is correct
35 Correct 284 ms 21624 KB Output is correct
36 Correct 164 ms 20080 KB Output is correct
37 Correct 205 ms 22104 KB Output is correct
38 Correct 304 ms 20304 KB Output is correct
39 Correct 398 ms 21328 KB Output is correct
40 Correct 299 ms 21072 KB Output is correct
41 Correct 36 ms 20472 KB Output is correct
42 Correct 35 ms 20500 KB Output is correct
43 Correct 46 ms 20224 KB Output is correct
44 Correct 46 ms 20208 KB Output is correct
45 Correct 37 ms 20464 KB Output is correct
46 Correct 44 ms 20288 KB Output is correct
47 Correct 45 ms 20212 KB Output is correct
48 Correct 32 ms 20480 KB Output is correct
49 Correct 33 ms 20108 KB Output is correct
50 Correct 35 ms 20480 KB Output is correct
51 Correct 40 ms 20472 KB Output is correct
52 Correct 48 ms 20208 KB Output is correct
53 Correct 39 ms 20236 KB Output is correct
54 Correct 46 ms 20216 KB Output is correct
55 Correct 43 ms 20240 KB Output is correct
56 Correct 39 ms 20208 KB Output is correct
57 Correct 36 ms 20280 KB Output is correct
58 Correct 34 ms 20208 KB Output is correct
59 Correct 41 ms 20280 KB Output is correct
60 Correct 42 ms 20236 KB Output is correct
61 Correct 39 ms 20212 KB Output is correct
62 Correct 52 ms 20400 KB Output is correct
63 Correct 45 ms 20232 KB Output is correct
64 Correct 38 ms 20480 KB Output is correct
65 Correct 41 ms 20208 KB Output is correct
66 Correct 39 ms 20212 KB Output is correct
67 Correct 42 ms 20256 KB Output is correct
68 Correct 60 ms 20240 KB Output is correct
69 Correct 46 ms 20492 KB Output is correct
70 Correct 50 ms 20348 KB Output is correct
71 Correct 312 ms 44532 KB Output is correct
72 Correct 346 ms 44804 KB Output is correct
73 Correct 407 ms 43400 KB Output is correct
74 Correct 561 ms 43508 KB Output is correct
75 Correct 360 ms 45540 KB Output is correct
76 Correct 572 ms 44196 KB Output is correct
77 Correct 526 ms 44092 KB Output is correct
78 Correct 260 ms 47736 KB Output is correct
79 Correct 234 ms 41736 KB Output is correct
80 Correct 378 ms 44684 KB Output is correct
81 Correct 437 ms 44528 KB Output is correct
82 Correct 547 ms 43504 KB Output is correct
83 Correct 333 ms 42732 KB Output is correct
84 Correct 530 ms 43736 KB Output is correct
85 Correct 508 ms 43760 KB Output is correct
86 Correct 223 ms 41612 KB Output is correct
87 Correct 309 ms 44860 KB Output is correct
88 Correct 248 ms 41696 KB Output is correct
89 Correct 388 ms 43248 KB Output is correct
90 Correct 398 ms 43720 KB Output is correct
91 Correct 339 ms 42740 KB Output is correct
92 Correct 563 ms 43884 KB Output is correct
93 Correct 481 ms 43768 KB Output is correct
94 Correct 239 ms 41712 KB Output is correct
95 Correct 460 ms 43604 KB Output is correct
96 Correct 464 ms 43792 KB Output is correct
97 Correct 467 ms 43700 KB Output is correct
98 Correct 443 ms 43720 KB Output is correct
99 Correct 431 ms 43724 KB Output is correct
100 Correct 456 ms 43596 KB Output is correct