답안 #1082583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1082583 2024-08-31T16:27:44 Z hahahaha Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
422 ms 39408 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")  // don't trust it
 
#ifdef LOCAL
#include "algo/debug.h"
#endif
 
using i64 = long long;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int L, Q;
  cin >> L >> Q;
 
  string S;
  cin >> S;
 
  vector<int> sub(1 << L);
  for (int i = 0; i < S.size(); ++i) {
    sub[i] = (S[i] - '0');
  }
  for (int i = 0; i < L; ++i) {
    for (int u = (1 << L) - 1; u >= 0; --u) {
      if (u >> i & 1) {
        sub[u] += sub[u ^ (1 << i)];
      }
    }
  }
 
  vector<int> super(1 << L);
  for (int i = 0; i < S.size(); ++i) {
    super[i] = (S[i] - '0');
  }
  for (int i = 0; i < L; ++i) {
    for (int u = 0; u < (1 << L); ++u) {
      if (!(u >> i & 1)) {
        super[u] += super[u ^ (1 << i)];
      }
    }
  }
 
  while (Q--) {
    string T;
    cin >> T;
    reverse(T.begin(), T.end());
    int cnt0 = count(T.begin(), T.end(), '0');
    int cnt1 = count(T.begin(), T.end(), '1');
    if (cnt0 <= L / 3) {
      int v = 0;
      int u = 0;
      for (int i = 0; i < L; ++i) {
        if (T[i] == '1') {
          v ^= (1 << i);
        } else if (T[i] == '0') {
          u ^= (1 << i);
        }
      }
      int ans = 0;
      for (int s = u; s > 0; s = (s - 1) & u) {
        ans += (__builtin_popcount(s) % 2 == 0 ? +1 : -1) * super[v | s];
      }
      ans += super[v];
      cout << ans << "\n";
    } else if (cnt1 <= L / 3) {
      int v = 0;
      int u = 0;
      for (int i = 0; i < L; ++i) {
        if (T[i] == '?') {
          v ^= (1 << i);
        } else if (T[i] == '1') {
          u ^= (1 << i);
        }
      }
      int ans = 0;
      for (int s = u; s > 0; s = (s - 1) & u) {
        ans += (__builtin_popcount(s) % 2 == 0 ? +1 : -1) * sub[v | (u - s)];
      }
      ans += sub[v | u];
      cout << ans << "\n";
    } else {
      int u = 0;
      int v = 0;
      for (int i = 0; i < L; ++i) {
        if (T[i] == '?') {
          u ^= (1 << i);
        } else if (T[i] == '1') {
          v ^= (1 << i);
        }
      }
      int ans = 0;
      for (int s = u; s > 0; s = (s - 1) & u) {
        ans += S[v | s] - '0';
      }
      ans += S[v] - '0';
      cout << ans << "\n";
    }
  }
 
  return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:25:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for (int i = 0; i < S.size(); ++i) {
      |                   ~~^~~~~~~~~~
snake_escaping.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int i = 0; i < S.size(); ++i) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 162 ms 15188 KB Output is correct
12 Correct 179 ms 14676 KB Output is correct
13 Correct 144 ms 13908 KB Output is correct
14 Correct 204 ms 14140 KB Output is correct
15 Correct 162 ms 15048 KB Output is correct
16 Correct 160 ms 14164 KB Output is correct
17 Correct 166 ms 14164 KB Output is correct
18 Correct 133 ms 16068 KB Output is correct
19 Correct 118 ms 13136 KB Output is correct
20 Correct 167 ms 14932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 162 ms 15188 KB Output is correct
12 Correct 179 ms 14676 KB Output is correct
13 Correct 144 ms 13908 KB Output is correct
14 Correct 204 ms 14140 KB Output is correct
15 Correct 162 ms 15048 KB Output is correct
16 Correct 160 ms 14164 KB Output is correct
17 Correct 166 ms 14164 KB Output is correct
18 Correct 133 ms 16068 KB Output is correct
19 Correct 118 ms 13136 KB Output is correct
20 Correct 167 ms 14932 KB Output is correct
21 Correct 173 ms 18232 KB Output is correct
22 Correct 184 ms 18516 KB Output is correct
23 Correct 170 ms 17236 KB Output is correct
24 Correct 169 ms 17200 KB Output is correct
25 Correct 190 ms 19132 KB Output is correct
26 Correct 206 ms 17748 KB Output is correct
27 Correct 197 ms 17496 KB Output is correct
28 Correct 151 ms 20052 KB Output is correct
29 Correct 123 ms 16072 KB Output is correct
30 Correct 190 ms 18200 KB Output is correct
31 Correct 195 ms 18260 KB Output is correct
32 Correct 185 ms 18000 KB Output is correct
33 Correct 185 ms 16972 KB Output is correct
34 Correct 186 ms 17052 KB Output is correct
35 Correct 250 ms 17488 KB Output is correct
36 Correct 117 ms 16172 KB Output is correct
37 Correct 169 ms 18008 KB Output is correct
38 Correct 147 ms 16232 KB Output is correct
39 Correct 178 ms 17280 KB Output is correct
40 Correct 193 ms 17232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 44 ms 12016 KB Output is correct
12 Correct 44 ms 11916 KB Output is correct
13 Correct 44 ms 12020 KB Output is correct
14 Correct 46 ms 12024 KB Output is correct
15 Correct 45 ms 11992 KB Output is correct
16 Correct 46 ms 12016 KB Output is correct
17 Correct 45 ms 12016 KB Output is correct
18 Correct 40 ms 12020 KB Output is correct
19 Correct 37 ms 11760 KB Output is correct
20 Correct 43 ms 11992 KB Output is correct
21 Correct 43 ms 12032 KB Output is correct
22 Correct 48 ms 11860 KB Output is correct
23 Correct 44 ms 12124 KB Output is correct
24 Correct 50 ms 12024 KB Output is correct
25 Correct 46 ms 12020 KB Output is correct
26 Correct 38 ms 11764 KB Output is correct
27 Correct 41 ms 12268 KB Output is correct
28 Correct 43 ms 11756 KB Output is correct
29 Correct 44 ms 11852 KB Output is correct
30 Correct 45 ms 11848 KB Output is correct
31 Correct 44 ms 12024 KB Output is correct
32 Correct 51 ms 12016 KB Output is correct
33 Correct 49 ms 12032 KB Output is correct
34 Correct 37 ms 11768 KB Output is correct
35 Correct 44 ms 12272 KB Output is correct
36 Correct 63 ms 11848 KB Output is correct
37 Correct 45 ms 12016 KB Output is correct
38 Correct 49 ms 11848 KB Output is correct
39 Correct 57 ms 12024 KB Output is correct
40 Correct 45 ms 12020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 162 ms 15188 KB Output is correct
12 Correct 179 ms 14676 KB Output is correct
13 Correct 144 ms 13908 KB Output is correct
14 Correct 204 ms 14140 KB Output is correct
15 Correct 162 ms 15048 KB Output is correct
16 Correct 160 ms 14164 KB Output is correct
17 Correct 166 ms 14164 KB Output is correct
18 Correct 133 ms 16068 KB Output is correct
19 Correct 118 ms 13136 KB Output is correct
20 Correct 167 ms 14932 KB Output is correct
21 Correct 173 ms 18232 KB Output is correct
22 Correct 184 ms 18516 KB Output is correct
23 Correct 170 ms 17236 KB Output is correct
24 Correct 169 ms 17200 KB Output is correct
25 Correct 190 ms 19132 KB Output is correct
26 Correct 206 ms 17748 KB Output is correct
27 Correct 197 ms 17496 KB Output is correct
28 Correct 151 ms 20052 KB Output is correct
29 Correct 123 ms 16072 KB Output is correct
30 Correct 190 ms 18200 KB Output is correct
31 Correct 195 ms 18260 KB Output is correct
32 Correct 185 ms 18000 KB Output is correct
33 Correct 185 ms 16972 KB Output is correct
34 Correct 186 ms 17052 KB Output is correct
35 Correct 250 ms 17488 KB Output is correct
36 Correct 117 ms 16172 KB Output is correct
37 Correct 169 ms 18008 KB Output is correct
38 Correct 147 ms 16232 KB Output is correct
39 Correct 178 ms 17280 KB Output is correct
40 Correct 193 ms 17232 KB Output is correct
41 Correct 44 ms 12016 KB Output is correct
42 Correct 44 ms 11916 KB Output is correct
43 Correct 44 ms 12020 KB Output is correct
44 Correct 46 ms 12024 KB Output is correct
45 Correct 45 ms 11992 KB Output is correct
46 Correct 46 ms 12016 KB Output is correct
47 Correct 45 ms 12016 KB Output is correct
48 Correct 40 ms 12020 KB Output is correct
49 Correct 37 ms 11760 KB Output is correct
50 Correct 43 ms 11992 KB Output is correct
51 Correct 43 ms 12032 KB Output is correct
52 Correct 48 ms 11860 KB Output is correct
53 Correct 44 ms 12124 KB Output is correct
54 Correct 50 ms 12024 KB Output is correct
55 Correct 46 ms 12020 KB Output is correct
56 Correct 38 ms 11764 KB Output is correct
57 Correct 41 ms 12268 KB Output is correct
58 Correct 43 ms 11756 KB Output is correct
59 Correct 44 ms 11852 KB Output is correct
60 Correct 45 ms 11848 KB Output is correct
61 Correct 44 ms 12024 KB Output is correct
62 Correct 51 ms 12016 KB Output is correct
63 Correct 49 ms 12032 KB Output is correct
64 Correct 37 ms 11768 KB Output is correct
65 Correct 44 ms 12272 KB Output is correct
66 Correct 63 ms 11848 KB Output is correct
67 Correct 45 ms 12016 KB Output is correct
68 Correct 49 ms 11848 KB Output is correct
69 Correct 57 ms 12024 KB Output is correct
70 Correct 45 ms 12020 KB Output is correct
71 Correct 292 ms 36328 KB Output is correct
72 Correct 288 ms 36336 KB Output is correct
73 Correct 317 ms 35060 KB Output is correct
74 Correct 367 ms 35172 KB Output is correct
75 Correct 280 ms 37360 KB Output is correct
76 Correct 393 ms 35576 KB Output is correct
77 Correct 348 ms 35412 KB Output is correct
78 Correct 217 ms 39408 KB Output is correct
79 Correct 204 ms 33272 KB Output is correct
80 Correct 309 ms 36344 KB Output is correct
81 Correct 327 ms 36204 KB Output is correct
82 Correct 387 ms 35320 KB Output is correct
83 Correct 301 ms 34544 KB Output is correct
84 Correct 422 ms 35516 KB Output is correct
85 Correct 369 ms 35568 KB Output is correct
86 Correct 202 ms 33268 KB Output is correct
87 Correct 288 ms 36340 KB Output is correct
88 Correct 214 ms 33264 KB Output is correct
89 Correct 327 ms 35056 KB Output is correct
90 Correct 346 ms 35200 KB Output is correct
91 Correct 265 ms 34152 KB Output is correct
92 Correct 419 ms 35644 KB Output is correct
93 Correct 381 ms 35404 KB Output is correct
94 Correct 184 ms 33292 KB Output is correct
95 Correct 336 ms 35316 KB Output is correct
96 Correct 342 ms 35416 KB Output is correct
97 Correct 329 ms 35316 KB Output is correct
98 Correct 330 ms 35348 KB Output is correct
99 Correct 335 ms 35416 KB Output is correct
100 Correct 337 ms 35316 KB Output is correct