# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548095 | 2022-04-12T11:34:45 Z | wmch13 | Snake Escaping (JOI18_snake_escaping) | C++14 | 1087 ms | 43308 KB |
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair <int, int> pii; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pair<ll,int>, null_type,less<pair<ll,int>>, rb_tree_tag,tree_order_statistics_node_update> const int INF = 1e7; const ll longINF = 1e17; const int mxN = 1 << 20; const int mxM = 1e5 + 9; const int MOD = 998244353; const double pi = acos (-1); void setIO (string s) { freopen ((s + ".in").c_str(), "r", stdin); freopen ((s + ".out").c_str(), "w", stdout); return; } int sub[mxN], sup[mxN], A[mxN]; bool oddParity (int x) { return __builtin_popcount (x) % 2; } void solve () { int L, Q; cin >> L >> Q; string s; cin >> s; for (int i = 0; i < (1 << L); i++) sub[i] = sup[i] = A[i] = (s[i] - '0'); for (int i = 0; i < L; i++) { for (int mask = 0; mask < (1 << L); mask++) { if (mask & (1 << i)) { sub[mask] += sub[mask ^ (1 << i)]; } else { sup[mask] += sup[mask ^ (1 << i)]; } } } while (Q--) { int zero = 0, one = 0, any = 0; for (int i = 0; i < L; i++) { char c; cin >> c; zero <<= 1; one <<= 1; any <<= 1; if (c == '0') { zero++; } else if (c == '1') { one++; } else any++; } int res = 0; if (__builtin_popcount (any) <= 6) { for (int mask = any; mask > 0; mask = (mask - 1) & any) res += A[mask | one]; res += A[one]; } else if (__builtin_popcount (zero) <= 6) { for (int mask = zero; mask > 0; mask = (mask - 1) & zero) res += sup[mask | one] * (oddParity (mask) ? -1 : 1); res += sup[one] * (oddParity (0) ? -1 : 1); } else { for (int mask = one; mask > 0; mask = (mask - 1) & one) res += sub[mask | any] * (oddParity (mask ^ one) ? -1 : 1); res += sub[any] * (oddParity (one) ? -1 : 1); } cout << res << "\n"; } return; } int main () { int t = 1; //cin >> t; ios_base::sync_with_stdio (0); cin.tie (0); //setIO ("deleg"); //preCalc (); while (t--) { //initialize common variables //go solve solve (); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 356 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 | 1 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 | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 356 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 | 315 ms | 4276 KB | Output is correct |
12 | Correct | 334 ms | 4044 KB | Output is correct |
13 | Correct | 343 ms | 3264 KB | Output is correct |
14 | Correct | 334 ms | 3396 KB | Output is correct |
15 | Correct | 366 ms | 4624 KB | Output is correct |
16 | Correct | 352 ms | 14212 KB | Output is correct |
17 | Correct | 347 ms | 14236 KB | Output is correct |
18 | Correct | 242 ms | 16080 KB | Output is correct |
19 | Correct | 295 ms | 13116 KB | Output is correct |
20 | Correct | 326 ms | 14716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 356 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 | 315 ms | 4276 KB | Output is correct |
12 | Correct | 334 ms | 4044 KB | Output is correct |
13 | Correct | 343 ms | 3264 KB | Output is correct |
14 | Correct | 334 ms | 3396 KB | Output is correct |
15 | Correct | 366 ms | 4624 KB | Output is correct |
16 | Correct | 352 ms | 14212 KB | Output is correct |
17 | Correct | 347 ms | 14236 KB | Output is correct |
18 | Correct | 242 ms | 16080 KB | Output is correct |
19 | Correct | 295 ms | 13116 KB | Output is correct |
20 | Correct | 326 ms | 14716 KB | Output is correct |
21 | Correct | 372 ms | 18108 KB | Output is correct |
22 | Correct | 457 ms | 18248 KB | Output is correct |
23 | Correct | 407 ms | 17432 KB | Output is correct |
24 | Correct | 439 ms | 17128 KB | Output is correct |
25 | Correct | 404 ms | 19040 KB | Output is correct |
26 | Correct | 435 ms | 17684 KB | Output is correct |
27 | Correct | 417 ms | 17488 KB | Output is correct |
28 | Correct | 270 ms | 20120 KB | Output is correct |
29 | Correct | 362 ms | 16104 KB | Output is correct |
30 | Correct | 383 ms | 18380 KB | Output is correct |
31 | Correct | 434 ms | 18124 KB | Output is correct |
32 | Correct | 412 ms | 18112 KB | Output is correct |
33 | Correct | 422 ms | 16972 KB | Output is correct |
34 | Correct | 390 ms | 17108 KB | Output is correct |
35 | Correct | 434 ms | 17552 KB | Output is correct |
36 | Correct | 290 ms | 16116 KB | Output is correct |
37 | Correct | 424 ms | 18140 KB | Output is correct |
38 | Correct | 355 ms | 16132 KB | Output is correct |
39 | Correct | 399 ms | 17292 KB | Output is correct |
40 | Correct | 398 ms | 17060 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 356 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 | 62 ms | 13932 KB | Output is correct |
12 | Correct | 67 ms | 13916 KB | Output is correct |
13 | Correct | 66 ms | 13904 KB | Output is correct |
14 | Correct | 73 ms | 13912 KB | Output is correct |
15 | Correct | 68 ms | 14032 KB | Output is correct |
16 | Correct | 96 ms | 13964 KB | Output is correct |
17 | Correct | 76 ms | 13932 KB | Output is correct |
18 | Correct | 42 ms | 14164 KB | Output is correct |
19 | Correct | 53 ms | 13860 KB | Output is correct |
20 | Correct | 59 ms | 13932 KB | Output is correct |
21 | Correct | 90 ms | 13960 KB | Output is correct |
22 | Correct | 80 ms | 13952 KB | Output is correct |
23 | Correct | 49 ms | 13852 KB | Output is correct |
24 | Correct | 61 ms | 13904 KB | Output is correct |
25 | Correct | 76 ms | 13896 KB | Output is correct |
26 | Correct | 47 ms | 13796 KB | Output is correct |
27 | Correct | 60 ms | 13932 KB | Output is correct |
28 | Correct | 56 ms | 13800 KB | Output is correct |
29 | Correct | 57 ms | 13904 KB | Output is correct |
30 | Correct | 61 ms | 13916 KB | Output is correct |
31 | Correct | 54 ms | 13868 KB | Output is correct |
32 | Correct | 89 ms | 13952 KB | Output is correct |
33 | Correct | 75 ms | 13960 KB | Output is correct |
34 | Correct | 47 ms | 13816 KB | Output is correct |
35 | Correct | 69 ms | 13916 KB | Output is correct |
36 | Correct | 70 ms | 13944 KB | Output is correct |
37 | Correct | 67 ms | 13912 KB | Output is correct |
38 | Correct | 70 ms | 13912 KB | Output is correct |
39 | Correct | 66 ms | 13852 KB | Output is correct |
40 | Correct | 67 ms | 13948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 356 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 | 315 ms | 4276 KB | Output is correct |
12 | Correct | 334 ms | 4044 KB | Output is correct |
13 | Correct | 343 ms | 3264 KB | Output is correct |
14 | Correct | 334 ms | 3396 KB | Output is correct |
15 | Correct | 366 ms | 4624 KB | Output is correct |
16 | Correct | 352 ms | 14212 KB | Output is correct |
17 | Correct | 347 ms | 14236 KB | Output is correct |
18 | Correct | 242 ms | 16080 KB | Output is correct |
19 | Correct | 295 ms | 13116 KB | Output is correct |
20 | Correct | 326 ms | 14716 KB | Output is correct |
21 | Correct | 372 ms | 18108 KB | Output is correct |
22 | Correct | 457 ms | 18248 KB | Output is correct |
23 | Correct | 407 ms | 17432 KB | Output is correct |
24 | Correct | 439 ms | 17128 KB | Output is correct |
25 | Correct | 404 ms | 19040 KB | Output is correct |
26 | Correct | 435 ms | 17684 KB | Output is correct |
27 | Correct | 417 ms | 17488 KB | Output is correct |
28 | Correct | 270 ms | 20120 KB | Output is correct |
29 | Correct | 362 ms | 16104 KB | Output is correct |
30 | Correct | 383 ms | 18380 KB | Output is correct |
31 | Correct | 434 ms | 18124 KB | Output is correct |
32 | Correct | 412 ms | 18112 KB | Output is correct |
33 | Correct | 422 ms | 16972 KB | Output is correct |
34 | Correct | 390 ms | 17108 KB | Output is correct |
35 | Correct | 434 ms | 17552 KB | Output is correct |
36 | Correct | 290 ms | 16116 KB | Output is correct |
37 | Correct | 424 ms | 18140 KB | Output is correct |
38 | Correct | 355 ms | 16132 KB | Output is correct |
39 | Correct | 399 ms | 17292 KB | Output is correct |
40 | Correct | 398 ms | 17060 KB | Output is correct |
41 | Correct | 62 ms | 13932 KB | Output is correct |
42 | Correct | 67 ms | 13916 KB | Output is correct |
43 | Correct | 66 ms | 13904 KB | Output is correct |
44 | Correct | 73 ms | 13912 KB | Output is correct |
45 | Correct | 68 ms | 14032 KB | Output is correct |
46 | Correct | 96 ms | 13964 KB | Output is correct |
47 | Correct | 76 ms | 13932 KB | Output is correct |
48 | Correct | 42 ms | 14164 KB | Output is correct |
49 | Correct | 53 ms | 13860 KB | Output is correct |
50 | Correct | 59 ms | 13932 KB | Output is correct |
51 | Correct | 90 ms | 13960 KB | Output is correct |
52 | Correct | 80 ms | 13952 KB | Output is correct |
53 | Correct | 49 ms | 13852 KB | Output is correct |
54 | Correct | 61 ms | 13904 KB | Output is correct |
55 | Correct | 76 ms | 13896 KB | Output is correct |
56 | Correct | 47 ms | 13796 KB | Output is correct |
57 | Correct | 60 ms | 13932 KB | Output is correct |
58 | Correct | 56 ms | 13800 KB | Output is correct |
59 | Correct | 57 ms | 13904 KB | Output is correct |
60 | Correct | 61 ms | 13916 KB | Output is correct |
61 | Correct | 54 ms | 13868 KB | Output is correct |
62 | Correct | 89 ms | 13952 KB | Output is correct |
63 | Correct | 75 ms | 13960 KB | Output is correct |
64 | Correct | 47 ms | 13816 KB | Output is correct |
65 | Correct | 69 ms | 13916 KB | Output is correct |
66 | Correct | 70 ms | 13944 KB | Output is correct |
67 | Correct | 67 ms | 13912 KB | Output is correct |
68 | Correct | 70 ms | 13912 KB | Output is correct |
69 | Correct | 66 ms | 13852 KB | Output is correct |
70 | Correct | 67 ms | 13948 KB | Output is correct |
71 | Correct | 592 ms | 40264 KB | Output is correct |
72 | Correct | 583 ms | 40484 KB | Output is correct |
73 | Correct | 675 ms | 38912 KB | Output is correct |
74 | Correct | 893 ms | 39332 KB | Output is correct |
75 | Correct | 559 ms | 41264 KB | Output is correct |
76 | Correct | 944 ms | 39724 KB | Output is correct |
77 | Correct | 958 ms | 39436 KB | Output is correct |
78 | Correct | 374 ms | 43308 KB | Output is correct |
79 | Correct | 551 ms | 37308 KB | Output is correct |
80 | Correct | 567 ms | 40408 KB | Output is correct |
81 | Correct | 723 ms | 40308 KB | Output is correct |
82 | Correct | 946 ms | 39320 KB | Output is correct |
83 | Correct | 522 ms | 38508 KB | Output is correct |
84 | Correct | 711 ms | 39364 KB | Output is correct |
85 | Correct | 965 ms | 39540 KB | Output is correct |
86 | Correct | 381 ms | 37252 KB | Output is correct |
87 | Correct | 584 ms | 40268 KB | Output is correct |
88 | Correct | 561 ms | 37324 KB | Output is correct |
89 | Correct | 646 ms | 39188 KB | Output is correct |
90 | Correct | 696 ms | 39236 KB | Output is correct |
91 | Correct | 566 ms | 38604 KB | Output is correct |
92 | Correct | 1087 ms | 39660 KB | Output is correct |
93 | Correct | 952 ms | 39640 KB | Output is correct |
94 | Correct | 360 ms | 37292 KB | Output is correct |
95 | Correct | 867 ms | 39548 KB | Output is correct |
96 | Correct | 838 ms | 39328 KB | Output is correct |
97 | Correct | 819 ms | 39340 KB | Output is correct |
98 | Correct | 822 ms | 39344 KB | Output is correct |
99 | Correct | 820 ms | 39360 KB | Output is correct |
100 | Correct | 814 ms | 39376 KB | Output is correct |