답안 #330399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
330399 2020-11-25T05:36:34 Z casperwang Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1139 ms 29232 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXL = 20;
const int MAXQ = 1000000;
int L, Q;
string str;
int val[1<<MAXL];
int sum0[1<<MAXL];
int sum1[1<<MAXL];
int cnt[1<<MAXL];
int p0, p1, pq;
int ans;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> L >> Q;
  cin >> str;
  for (int i = 0; i < (1<<L); i++) {
    val[i] = sum0[i] = sum1[i] = str[i] - '0';
    cnt[i] = cnt[i>>1] + (i&1);
  }
  for (int i = 0; i < L; i++) {
    for (int j = 0; j < (1<<L); j++) {
      if ((1<<i) & j) {
        sum0[j] += sum0[(1<<i) ^ j];
        sum1[(1<<i) ^ j] += sum1[j];
      }
    }
  }
  for (int i = 0; i < Q; i++) {
    cin >> str;
    p0 = p1 = pq = 0;
    for (int j = 0; j < L; j++) {
      if (str[L-1-j] == '0') p0 |= (1<<j);
      if (str[L-1-j] == '1') p1 |= (1<<j);
      if (str[L-1-j] == '?') pq |= (1<<j);
    }
    ans = 0;
    if (cnt[p0] <= 6) {
      for (int j = p0; ; j=(j-1)&p0) {
        if (cnt[j] & 1) ans -= sum1[p1 | j];
        else ans += sum1[p1 | j];
        if (!j) break;
      }
    } else if (cnt[p1] <= 6) {
      for (int j = p1; ; j=(j-1)&p1) {
        if (cnt[p1 ^ j] & 1) ans -= sum0[pq | j];
        else ans += sum0[pq | j];
        if (!j) break;
      }
    } else {
      for (int j = pq; ; j=(j-1)&pq) {
        ans += val[p1 | j];
        if (!j) break;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 239 ms 15212 KB Output is correct
12 Correct 306 ms 15084 KB Output is correct
13 Correct 323 ms 14052 KB Output is correct
14 Correct 295 ms 14188 KB Output is correct
15 Correct 258 ms 15212 KB Output is correct
16 Correct 289 ms 14344 KB Output is correct
17 Correct 319 ms 14336 KB Output is correct
18 Correct 213 ms 16108 KB Output is correct
19 Correct 282 ms 13292 KB Output is correct
20 Correct 248 ms 14828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 239 ms 15212 KB Output is correct
12 Correct 306 ms 15084 KB Output is correct
13 Correct 323 ms 14052 KB Output is correct
14 Correct 295 ms 14188 KB Output is correct
15 Correct 258 ms 15212 KB Output is correct
16 Correct 289 ms 14344 KB Output is correct
17 Correct 319 ms 14336 KB Output is correct
18 Correct 213 ms 16108 KB Output is correct
19 Correct 282 ms 13292 KB Output is correct
20 Correct 248 ms 14828 KB Output is correct
21 Correct 273 ms 18284 KB Output is correct
22 Correct 351 ms 18540 KB Output is correct
23 Correct 447 ms 17388 KB Output is correct
24 Correct 371 ms 17260 KB Output is correct
25 Correct 296 ms 19308 KB Output is correct
26 Correct 345 ms 17772 KB Output is correct
27 Correct 373 ms 17772 KB Output is correct
28 Correct 242 ms 20332 KB Output is correct
29 Correct 397 ms 16236 KB Output is correct
30 Correct 292 ms 18412 KB Output is correct
31 Correct 337 ms 18412 KB Output is correct
32 Correct 338 ms 18284 KB Output is correct
33 Correct 299 ms 17132 KB Output is correct
34 Correct 369 ms 17308 KB Output is correct
35 Correct 377 ms 17652 KB Output is correct
36 Correct 212 ms 16364 KB Output is correct
37 Correct 283 ms 18284 KB Output is correct
38 Correct 370 ms 16364 KB Output is correct
39 Correct 338 ms 17388 KB Output is correct
40 Correct 341 ms 17388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 60 ms 20240 KB Output is correct
12 Correct 64 ms 20256 KB Output is correct
13 Correct 80 ms 20240 KB Output is correct
14 Correct 95 ms 20112 KB Output is correct
15 Correct 62 ms 20240 KB Output is correct
16 Correct 89 ms 20240 KB Output is correct
17 Correct 89 ms 20240 KB Output is correct
18 Correct 54 ms 20368 KB Output is correct
19 Correct 62 ms 20112 KB Output is correct
20 Correct 61 ms 20240 KB Output is correct
21 Correct 75 ms 20240 KB Output is correct
22 Correct 87 ms 20260 KB Output is correct
23 Correct 62 ms 20112 KB Output is correct
24 Correct 93 ms 20112 KB Output is correct
25 Correct 91 ms 20240 KB Output is correct
26 Correct 52 ms 20112 KB Output is correct
27 Correct 62 ms 20240 KB Output is correct
28 Correct 68 ms 20112 KB Output is correct
29 Correct 77 ms 20112 KB Output is correct
30 Correct 85 ms 20112 KB Output is correct
31 Correct 68 ms 20112 KB Output is correct
32 Correct 100 ms 20240 KB Output is correct
33 Correct 88 ms 20240 KB Output is correct
34 Correct 52 ms 20112 KB Output is correct
35 Correct 82 ms 20112 KB Output is correct
36 Correct 81 ms 20240 KB Output is correct
37 Correct 80 ms 20240 KB Output is correct
38 Correct 81 ms 20240 KB Output is correct
39 Correct 79 ms 20112 KB Output is correct
40 Correct 80 ms 20112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 239 ms 15212 KB Output is correct
12 Correct 306 ms 15084 KB Output is correct
13 Correct 323 ms 14052 KB Output is correct
14 Correct 295 ms 14188 KB Output is correct
15 Correct 258 ms 15212 KB Output is correct
16 Correct 289 ms 14344 KB Output is correct
17 Correct 319 ms 14336 KB Output is correct
18 Correct 213 ms 16108 KB Output is correct
19 Correct 282 ms 13292 KB Output is correct
20 Correct 248 ms 14828 KB Output is correct
21 Correct 273 ms 18284 KB Output is correct
22 Correct 351 ms 18540 KB Output is correct
23 Correct 447 ms 17388 KB Output is correct
24 Correct 371 ms 17260 KB Output is correct
25 Correct 296 ms 19308 KB Output is correct
26 Correct 345 ms 17772 KB Output is correct
27 Correct 373 ms 17772 KB Output is correct
28 Correct 242 ms 20332 KB Output is correct
29 Correct 397 ms 16236 KB Output is correct
30 Correct 292 ms 18412 KB Output is correct
31 Correct 337 ms 18412 KB Output is correct
32 Correct 338 ms 18284 KB Output is correct
33 Correct 299 ms 17132 KB Output is correct
34 Correct 369 ms 17308 KB Output is correct
35 Correct 377 ms 17652 KB Output is correct
36 Correct 212 ms 16364 KB Output is correct
37 Correct 283 ms 18284 KB Output is correct
38 Correct 370 ms 16364 KB Output is correct
39 Correct 338 ms 17388 KB Output is correct
40 Correct 341 ms 17388 KB Output is correct
41 Correct 60 ms 20240 KB Output is correct
42 Correct 64 ms 20256 KB Output is correct
43 Correct 80 ms 20240 KB Output is correct
44 Correct 95 ms 20112 KB Output is correct
45 Correct 62 ms 20240 KB Output is correct
46 Correct 89 ms 20240 KB Output is correct
47 Correct 89 ms 20240 KB Output is correct
48 Correct 54 ms 20368 KB Output is correct
49 Correct 62 ms 20112 KB Output is correct
50 Correct 61 ms 20240 KB Output is correct
51 Correct 75 ms 20240 KB Output is correct
52 Correct 87 ms 20260 KB Output is correct
53 Correct 62 ms 20112 KB Output is correct
54 Correct 93 ms 20112 KB Output is correct
55 Correct 91 ms 20240 KB Output is correct
56 Correct 52 ms 20112 KB Output is correct
57 Correct 62 ms 20240 KB Output is correct
58 Correct 68 ms 20112 KB Output is correct
59 Correct 77 ms 20112 KB Output is correct
60 Correct 85 ms 20112 KB Output is correct
61 Correct 68 ms 20112 KB Output is correct
62 Correct 100 ms 20240 KB Output is correct
63 Correct 88 ms 20240 KB Output is correct
64 Correct 52 ms 20112 KB Output is correct
65 Correct 82 ms 20112 KB Output is correct
66 Correct 81 ms 20240 KB Output is correct
67 Correct 80 ms 20240 KB Output is correct
68 Correct 81 ms 20240 KB Output is correct
69 Correct 79 ms 20112 KB Output is correct
70 Correct 80 ms 20112 KB Output is correct
71 Correct 442 ms 25440 KB Output is correct
72 Correct 510 ms 25616 KB Output is correct
73 Correct 744 ms 24464 KB Output is correct
74 Correct 978 ms 24592 KB Output is correct
75 Correct 454 ms 26896 KB Output is correct
76 Correct 1018 ms 25744 KB Output is correct
77 Correct 965 ms 25232 KB Output is correct
78 Correct 292 ms 29232 KB Output is correct
79 Correct 454 ms 23056 KB Output is correct
80 Correct 436 ms 26128 KB Output is correct
81 Correct 679 ms 26128 KB Output is correct
82 Correct 954 ms 25232 KB Output is correct
83 Correct 450 ms 24208 KB Output is correct
84 Correct 1076 ms 25104 KB Output is correct
85 Correct 960 ms 25104 KB Output is correct
86 Correct 260 ms 23056 KB Output is correct
87 Correct 466 ms 26000 KB Output is correct
88 Correct 510 ms 23056 KB Output is correct
89 Correct 683 ms 24592 KB Output is correct
90 Correct 833 ms 24908 KB Output is correct
91 Correct 552 ms 24180 KB Output is correct
92 Correct 1139 ms 25488 KB Output is correct
93 Correct 969 ms 25408 KB Output is correct
94 Correct 275 ms 23056 KB Output is correct
95 Correct 809 ms 24976 KB Output is correct
96 Correct 821 ms 24592 KB Output is correct
97 Correct 804 ms 26768 KB Output is correct
98 Correct 803 ms 26256 KB Output is correct
99 Correct 810 ms 25232 KB Output is correct
100 Correct 808 ms 25092 KB Output is correct