Submission #654657

# Submission time Handle Problem Language Result Execution time Memory
654657 2022-11-01T06:17:33 Z lunchbox1 Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
696 ms 43472 KB
/*
 Snake Escaping
 https://oj.uz/problem/view/JOI18_snake_escaping
*/
#include <bits/stdc++.h>
using namespace std;

const int L = 20, N = 1 << L;

int main() {
 ios::sync_with_stdio(0), cin.tie(0);
 int l, q; cin >> l >> q;
 string s; cin >> s;
 int n = 1 << l;
 static int f[N], g[N], c[N];
 for (int i = 0; i < n; i++)
  f[i] += s[i] - '0', g[i] += s[i] - '0';
 for (int i = 1; i < n; i++)
  c[i] = c[i & (i - 1)] + 1;
 for (int b = 0; b < l; b++)
  for (int i = 0; i < n; i++)
   if (i >> b & 1) {
    f[i] += f[i ^ (1 << b)];
    g[i ^ (1 << b)] += g[i];
   }
 while (q--) {
  string t; cin >> t;
  reverse(t.begin(), t.end());
  int i0 = 0, i1 = 0, iq = 0;
  for (int b = 0; b < l; b++)
   if (t[b] == '0') i0 |= 1 << b;
   else if (t[b] == '1') i1 |= 1 << b;
   else iq |= 1 << b;
  int v = 0;
  if (c[iq] <= 7) {
   for (int t = iq; ; t = (t - 1) & iq) {
    v += s[t | i1] - '0';
    if (t == 0) break;
   }
  } else if (c[i0] <= 7) {
   for (int t = i0; ; t = (t - 1) & i0) {
    v += (c[t] % 2 ? -1 : +1) * g[t | i1];
    if (t == 0) break;
   }
  } else {
   for (int t = i1; ; t = (t - 1) & i1) {
    v += (c[t] % 2 ? -1 : +1) * f[(t ^ i1) | iq];
    if (t == 0) break;
   }
  }
  cout << v << '\n';
 }
 return 0;
}
# 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 336 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 300 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 336 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 300 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 239 ms 15020 KB Output is correct
12 Correct 256 ms 14788 KB Output is correct
13 Correct 231 ms 14060 KB Output is correct
14 Correct 224 ms 14048 KB Output is correct
15 Correct 279 ms 15100 KB Output is correct
16 Correct 260 ms 14176 KB Output is correct
17 Correct 254 ms 14244 KB Output is correct
18 Correct 166 ms 16072 KB Output is correct
19 Correct 201 ms 13108 KB Output is correct
20 Correct 271 ms 14684 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 336 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 300 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 239 ms 15020 KB Output is correct
12 Correct 256 ms 14788 KB Output is correct
13 Correct 231 ms 14060 KB Output is correct
14 Correct 224 ms 14048 KB Output is correct
15 Correct 279 ms 15100 KB Output is correct
16 Correct 260 ms 14176 KB Output is correct
17 Correct 254 ms 14244 KB Output is correct
18 Correct 166 ms 16072 KB Output is correct
19 Correct 201 ms 13108 KB Output is correct
20 Correct 271 ms 14684 KB Output is correct
21 Correct 366 ms 18160 KB Output is correct
22 Correct 295 ms 18296 KB Output is correct
23 Correct 274 ms 17248 KB Output is correct
24 Correct 269 ms 17100 KB Output is correct
25 Correct 232 ms 19148 KB Output is correct
26 Correct 293 ms 17576 KB Output is correct
27 Correct 294 ms 17596 KB Output is correct
28 Correct 174 ms 20052 KB Output is correct
29 Correct 214 ms 16132 KB Output is correct
30 Correct 302 ms 18204 KB Output is correct
31 Correct 313 ms 18124 KB Output is correct
32 Correct 281 ms 18208 KB Output is correct
33 Correct 241 ms 17100 KB Output is correct
34 Correct 284 ms 17084 KB Output is correct
35 Correct 298 ms 17676 KB Output is correct
36 Correct 184 ms 16148 KB Output is correct
37 Correct 303 ms 18080 KB Output is correct
38 Correct 223 ms 16076 KB Output is correct
39 Correct 268 ms 17216 KB Output is correct
40 Correct 261 ms 17276 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 336 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 300 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 52 ms 16020 KB Output is correct
12 Correct 59 ms 16028 KB Output is correct
13 Correct 67 ms 15976 KB Output is correct
14 Correct 66 ms 15980 KB Output is correct
15 Correct 58 ms 16044 KB Output is correct
16 Correct 65 ms 15964 KB Output is correct
17 Correct 65 ms 15952 KB Output is correct
18 Correct 45 ms 16172 KB Output is correct
19 Correct 48 ms 15852 KB Output is correct
20 Correct 56 ms 15980 KB Output is correct
21 Correct 70 ms 15996 KB Output is correct
22 Correct 58 ms 16020 KB Output is correct
23 Correct 51 ms 16004 KB Output is correct
24 Correct 57 ms 15968 KB Output is correct
25 Correct 63 ms 15980 KB Output is correct
26 Correct 43 ms 15852 KB Output is correct
27 Correct 50 ms 15980 KB Output is correct
28 Correct 49 ms 15824 KB Output is correct
29 Correct 56 ms 15976 KB Output is correct
30 Correct 53 ms 15952 KB Output is correct
31 Correct 49 ms 15980 KB Output is correct
32 Correct 61 ms 15936 KB Output is correct
33 Correct 69 ms 15960 KB Output is correct
34 Correct 42 ms 15820 KB Output is correct
35 Correct 56 ms 15980 KB Output is correct
36 Correct 59 ms 16008 KB Output is correct
37 Correct 57 ms 16028 KB Output is correct
38 Correct 55 ms 15980 KB Output is correct
39 Correct 63 ms 16040 KB Output is correct
40 Correct 56 ms 16016 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 336 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 300 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 239 ms 15020 KB Output is correct
12 Correct 256 ms 14788 KB Output is correct
13 Correct 231 ms 14060 KB Output is correct
14 Correct 224 ms 14048 KB Output is correct
15 Correct 279 ms 15100 KB Output is correct
16 Correct 260 ms 14176 KB Output is correct
17 Correct 254 ms 14244 KB Output is correct
18 Correct 166 ms 16072 KB Output is correct
19 Correct 201 ms 13108 KB Output is correct
20 Correct 271 ms 14684 KB Output is correct
21 Correct 366 ms 18160 KB Output is correct
22 Correct 295 ms 18296 KB Output is correct
23 Correct 274 ms 17248 KB Output is correct
24 Correct 269 ms 17100 KB Output is correct
25 Correct 232 ms 19148 KB Output is correct
26 Correct 293 ms 17576 KB Output is correct
27 Correct 294 ms 17596 KB Output is correct
28 Correct 174 ms 20052 KB Output is correct
29 Correct 214 ms 16132 KB Output is correct
30 Correct 302 ms 18204 KB Output is correct
31 Correct 313 ms 18124 KB Output is correct
32 Correct 281 ms 18208 KB Output is correct
33 Correct 241 ms 17100 KB Output is correct
34 Correct 284 ms 17084 KB Output is correct
35 Correct 298 ms 17676 KB Output is correct
36 Correct 184 ms 16148 KB Output is correct
37 Correct 303 ms 18080 KB Output is correct
38 Correct 223 ms 16076 KB Output is correct
39 Correct 268 ms 17216 KB Output is correct
40 Correct 261 ms 17276 KB Output is correct
41 Correct 52 ms 16020 KB Output is correct
42 Correct 59 ms 16028 KB Output is correct
43 Correct 67 ms 15976 KB Output is correct
44 Correct 66 ms 15980 KB Output is correct
45 Correct 58 ms 16044 KB Output is correct
46 Correct 65 ms 15964 KB Output is correct
47 Correct 65 ms 15952 KB Output is correct
48 Correct 45 ms 16172 KB Output is correct
49 Correct 48 ms 15852 KB Output is correct
50 Correct 56 ms 15980 KB Output is correct
51 Correct 70 ms 15996 KB Output is correct
52 Correct 58 ms 16020 KB Output is correct
53 Correct 51 ms 16004 KB Output is correct
54 Correct 57 ms 15968 KB Output is correct
55 Correct 63 ms 15980 KB Output is correct
56 Correct 43 ms 15852 KB Output is correct
57 Correct 50 ms 15980 KB Output is correct
58 Correct 49 ms 15824 KB Output is correct
59 Correct 56 ms 15976 KB Output is correct
60 Correct 53 ms 15952 KB Output is correct
61 Correct 49 ms 15980 KB Output is correct
62 Correct 61 ms 15936 KB Output is correct
63 Correct 69 ms 15960 KB Output is correct
64 Correct 42 ms 15820 KB Output is correct
65 Correct 56 ms 15980 KB Output is correct
66 Correct 59 ms 16008 KB Output is correct
67 Correct 57 ms 16028 KB Output is correct
68 Correct 55 ms 15980 KB Output is correct
69 Correct 63 ms 16040 KB Output is correct
70 Correct 56 ms 16016 KB Output is correct
71 Correct 432 ms 40344 KB Output is correct
72 Correct 502 ms 40392 KB Output is correct
73 Correct 466 ms 38924 KB Output is correct
74 Correct 596 ms 39284 KB Output is correct
75 Correct 442 ms 41412 KB Output is correct
76 Correct 696 ms 39736 KB Output is correct
77 Correct 628 ms 39556 KB Output is correct
78 Correct 265 ms 43472 KB Output is correct
79 Correct 360 ms 37292 KB Output is correct
80 Correct 427 ms 40508 KB Output is correct
81 Correct 626 ms 40360 KB Output is correct
82 Correct 607 ms 39372 KB Output is correct
83 Correct 383 ms 38460 KB Output is correct
84 Correct 479 ms 39308 KB Output is correct
85 Correct 586 ms 39548 KB Output is correct
86 Correct 255 ms 37272 KB Output is correct
87 Correct 404 ms 40392 KB Output is correct
88 Correct 351 ms 37400 KB Output is correct
89 Correct 450 ms 39120 KB Output is correct
90 Correct 461 ms 39324 KB Output is correct
91 Correct 378 ms 38652 KB Output is correct
92 Correct 615 ms 39776 KB Output is correct
93 Correct 642 ms 39532 KB Output is correct
94 Correct 249 ms 37292 KB Output is correct
95 Correct 521 ms 39448 KB Output is correct
96 Correct 532 ms 39460 KB Output is correct
97 Correct 531 ms 39500 KB Output is correct
98 Correct 488 ms 39424 KB Output is correct
99 Correct 507 ms 39332 KB Output is correct
100 Correct 529 ms 39472 KB Output is correct