# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
675740 | 2022-12-27T19:28:32 Z | MilosMilutinovic | Snake Escaping (JOI18_snake_escaping) | C++14 | 2000 ms | 14984 KB |
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <array> using namespace std; #ifdef LOCAL #define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);} #else #define eprintf(...) 42 #endif using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template<typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } const int N = (1 << 21); int n, q; char s[N]; char t[N]; int sub[N]; int sup[N]; int main() { startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); scanf("%d%d", &n, &q); scanf("%s", s); for (int i = 0; i < (1 << n); i++) { sub[i] = (int)(s[i] - '0'); sup[i] = (int)(s[i] - '0'); } for (int i = 0; i < n; i++) for (int mask = 0; mask < (1 << n); mask++) if (mask >> i & 1) sub[mask] += sub[mask ^ (1 << i)]; for (int i = 0; i < n; i++) for (int mask = (1 << n) - 1; mask >= 0; mask--) if (!(mask >> i & 1)) sup[mask] += sup[mask ^ (1 << i)]; while(q--) { scanf("%s", t); reverse(t, t + n); vector<int> zero, one, qmark; for (int i = 0; i < n; i++) { if (t[i] == '0') zero.push_back(i); if (t[i] == '1') one.push_back(i); if (t[i] == '?') qmark.push_back(i); } int tmask = 0; for (int i = 0; i < n; i++) if (t[i] == '1') tmask += (1 << i); int ans = 0; if (qmark.size() <= 6) { int sz = qmark.size(); for (int mask = 0; mask < (1 << sz); mask++) { int nmask = tmask; for (int i = 0; i < sz; i++) if (mask >> i & 1) nmask += (1 << qmark[i]); ans += (int)(s[nmask] - '0'); } } else if (zero.size() <= 6) { int sz = zero.size(); for (int mask = 0; mask < (1 << sz); mask++) { int nmask = tmask; for (int i = 0; i < sz; i++) if (mask >> i & 1) nmask += (1 << zero[i]); ans += sup[nmask] * (__builtin_popcount(mask) % 2 == 0 ? 1 : -1); } } else { assert(one.size() <= 6); int sz = one.size(); tmask = 0; for (int i = 0; i < n; i++) if (t[i] == '?') tmask += (1 << i); for (int mask = 0; mask < (1 << sz); mask++) { int nmask = tmask; for (int i = 0; i < sz; i++) if (mask >> i & 1) nmask += (1 << one[i]); ans += sub[nmask] * ((sz - __builtin_popcount(mask)) % 2 == 0 ? 1 : -1); } } printf("%d\n", ans); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 807 ms | 4404 KB | Output is correct |
12 | Correct | 713 ms | 4012 KB | Output is correct |
13 | Correct | 641 ms | 3240 KB | Output is correct |
14 | Correct | 614 ms | 3412 KB | Output is correct |
15 | Correct | 1108 ms | 4376 KB | Output is correct |
16 | Correct | 723 ms | 3432 KB | Output is correct |
17 | Correct | 706 ms | 3508 KB | Output is correct |
18 | Correct | 380 ms | 5300 KB | Output is correct |
19 | Correct | 532 ms | 2212 KB | Output is correct |
20 | Correct | 771 ms | 3908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 807 ms | 4404 KB | Output is correct |
12 | Correct | 713 ms | 4012 KB | Output is correct |
13 | Correct | 641 ms | 3240 KB | Output is correct |
14 | Correct | 614 ms | 3412 KB | Output is correct |
15 | Correct | 1108 ms | 4376 KB | Output is correct |
16 | Correct | 723 ms | 3432 KB | Output is correct |
17 | Correct | 706 ms | 3508 KB | Output is correct |
18 | Correct | 380 ms | 5300 KB | Output is correct |
19 | Correct | 532 ms | 2212 KB | Output is correct |
20 | Correct | 771 ms | 3908 KB | Output is correct |
21 | Correct | 610 ms | 4312 KB | Output is correct |
22 | Correct | 950 ms | 4564 KB | Output is correct |
23 | Correct | 821 ms | 3580 KB | Output is correct |
24 | Correct | 776 ms | 3360 KB | Output is correct |
25 | Correct | 636 ms | 5504 KB | Output is correct |
26 | Correct | 913 ms | 3788 KB | Output is correct |
27 | Correct | 906 ms | 3904 KB | Output is correct |
28 | Correct | 365 ms | 6348 KB | Output is correct |
29 | Correct | 564 ms | 2432 KB | Output is correct |
30 | Correct | 808 ms | 4560 KB | Output is correct |
31 | Correct | 1229 ms | 4428 KB | Output is correct |
32 | Correct | 894 ms | 4572 KB | Output is correct |
33 | Correct | 634 ms | 3200 KB | Output is correct |
34 | Correct | 761 ms | 3404 KB | Output is correct |
35 | Correct | 910 ms | 3896 KB | Output is correct |
36 | Correct | 370 ms | 2308 KB | Output is correct |
37 | Correct | 1106 ms | 4468 KB | Output is correct |
38 | Correct | 582 ms | 2396 KB | Output is correct |
39 | Correct | 806 ms | 3708 KB | Output is correct |
40 | Correct | 751 ms | 3464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 89 ms | 9792 KB | Output is correct |
12 | Correct | 97 ms | 9792 KB | Output is correct |
13 | Correct | 118 ms | 9664 KB | Output is correct |
14 | Correct | 141 ms | 9688 KB | Output is correct |
15 | Correct | 93 ms | 9848 KB | Output is correct |
16 | Correct | 125 ms | 9820 KB | Output is correct |
17 | Correct | 126 ms | 9660 KB | Output is correct |
18 | Correct | 73 ms | 9952 KB | Output is correct |
19 | Correct | 84 ms | 9544 KB | Output is correct |
20 | Correct | 91 ms | 9760 KB | Output is correct |
21 | Correct | 110 ms | 9784 KB | Output is correct |
22 | Correct | 128 ms | 9824 KB | Output is correct |
23 | Correct | 93 ms | 9660 KB | Output is correct |
24 | Correct | 123 ms | 9716 KB | Output is correct |
25 | Correct | 123 ms | 9732 KB | Output is correct |
26 | Correct | 68 ms | 9536 KB | Output is correct |
27 | Correct | 89 ms | 9676 KB | Output is correct |
28 | Correct | 84 ms | 9552 KB | Output is correct |
29 | Correct | 106 ms | 9676 KB | Output is correct |
30 | Correct | 124 ms | 9664 KB | Output is correct |
31 | Correct | 94 ms | 9664 KB | Output is correct |
32 | Correct | 134 ms | 9676 KB | Output is correct |
33 | Correct | 122 ms | 9672 KB | Output is correct |
34 | Correct | 69 ms | 9536 KB | Output is correct |
35 | Correct | 113 ms | 9712 KB | Output is correct |
36 | Correct | 113 ms | 9708 KB | Output is correct |
37 | Correct | 110 ms | 9744 KB | Output is correct |
38 | Correct | 116 ms | 9624 KB | Output is correct |
39 | Correct | 113 ms | 9820 KB | Output is correct |
40 | Correct | 112 ms | 9708 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 807 ms | 4404 KB | Output is correct |
12 | Correct | 713 ms | 4012 KB | Output is correct |
13 | Correct | 641 ms | 3240 KB | Output is correct |
14 | Correct | 614 ms | 3412 KB | Output is correct |
15 | Correct | 1108 ms | 4376 KB | Output is correct |
16 | Correct | 723 ms | 3432 KB | Output is correct |
17 | Correct | 706 ms | 3508 KB | Output is correct |
18 | Correct | 380 ms | 5300 KB | Output is correct |
19 | Correct | 532 ms | 2212 KB | Output is correct |
20 | Correct | 771 ms | 3908 KB | Output is correct |
21 | Correct | 610 ms | 4312 KB | Output is correct |
22 | Correct | 950 ms | 4564 KB | Output is correct |
23 | Correct | 821 ms | 3580 KB | Output is correct |
24 | Correct | 776 ms | 3360 KB | Output is correct |
25 | Correct | 636 ms | 5504 KB | Output is correct |
26 | Correct | 913 ms | 3788 KB | Output is correct |
27 | Correct | 906 ms | 3904 KB | Output is correct |
28 | Correct | 365 ms | 6348 KB | Output is correct |
29 | Correct | 564 ms | 2432 KB | Output is correct |
30 | Correct | 808 ms | 4560 KB | Output is correct |
31 | Correct | 1229 ms | 4428 KB | Output is correct |
32 | Correct | 894 ms | 4572 KB | Output is correct |
33 | Correct | 634 ms | 3200 KB | Output is correct |
34 | Correct | 761 ms | 3404 KB | Output is correct |
35 | Correct | 910 ms | 3896 KB | Output is correct |
36 | Correct | 370 ms | 2308 KB | Output is correct |
37 | Correct | 1106 ms | 4468 KB | Output is correct |
38 | Correct | 582 ms | 2396 KB | Output is correct |
39 | Correct | 806 ms | 3708 KB | Output is correct |
40 | Correct | 751 ms | 3464 KB | Output is correct |
41 | Correct | 89 ms | 9792 KB | Output is correct |
42 | Correct | 97 ms | 9792 KB | Output is correct |
43 | Correct | 118 ms | 9664 KB | Output is correct |
44 | Correct | 141 ms | 9688 KB | Output is correct |
45 | Correct | 93 ms | 9848 KB | Output is correct |
46 | Correct | 125 ms | 9820 KB | Output is correct |
47 | Correct | 126 ms | 9660 KB | Output is correct |
48 | Correct | 73 ms | 9952 KB | Output is correct |
49 | Correct | 84 ms | 9544 KB | Output is correct |
50 | Correct | 91 ms | 9760 KB | Output is correct |
51 | Correct | 110 ms | 9784 KB | Output is correct |
52 | Correct | 128 ms | 9824 KB | Output is correct |
53 | Correct | 93 ms | 9660 KB | Output is correct |
54 | Correct | 123 ms | 9716 KB | Output is correct |
55 | Correct | 123 ms | 9732 KB | Output is correct |
56 | Correct | 68 ms | 9536 KB | Output is correct |
57 | Correct | 89 ms | 9676 KB | Output is correct |
58 | Correct | 84 ms | 9552 KB | Output is correct |
59 | Correct | 106 ms | 9676 KB | Output is correct |
60 | Correct | 124 ms | 9664 KB | Output is correct |
61 | Correct | 94 ms | 9664 KB | Output is correct |
62 | Correct | 134 ms | 9676 KB | Output is correct |
63 | Correct | 122 ms | 9672 KB | Output is correct |
64 | Correct | 69 ms | 9536 KB | Output is correct |
65 | Correct | 113 ms | 9712 KB | Output is correct |
66 | Correct | 113 ms | 9708 KB | Output is correct |
67 | Correct | 110 ms | 9744 KB | Output is correct |
68 | Correct | 116 ms | 9624 KB | Output is correct |
69 | Correct | 113 ms | 9820 KB | Output is correct |
70 | Correct | 112 ms | 9708 KB | Output is correct |
71 | Correct | 900 ms | 14468 KB | Output is correct |
72 | Correct | 971 ms | 14632 KB | Output is correct |
73 | Correct | 1242 ms | 13140 KB | Output is correct |
74 | Execution timed out | 2013 ms | 14984 KB | Time limit exceeded |
75 | Halted | 0 ms | 0 KB | - |