답안 #1054810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054810 2024-08-12T12:20:23 Z nima_aryan Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 25844 KB
/**
 *    author:  NimaAryan
 *    created: 2024-08-12 13:06:22  
**/
#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 ans = 0;
      for (int u = 0; u < (1 << cnt0); ++u) {
        int v = 0;
        for (int i = 0, j = 0; i < L; ++i) {
          if (T[i] == '0') {
            if (u >> j & 1) {
              v ^= (1 << i);
            } else {

            }
            ++j;
          } else if (T[i] == '1') {
            v ^= (1 << i);
          } else if (T[i] == '?') {

          }
        }
        ans += (__builtin_popcount(u) % 2 == 0 ? +1 : -1) * super[v];
      }
      cout << ans << "\n";
    } else if (cnt1 <= L / 3) {
      int ans = 0;
      for (int u = 0; u < (1 << cnt1); ++u) {
        int v = 0;
        for (int i = 0, j = 0; i < L; ++i) {
          if (T[i] == '1') {
            if (u >> j & 1) {

            } else {
              v ^= (1 << i) * 1;
            }
            ++j;
          } else if (T[i] == '0') {

          } else if (T[i] == '?') {
            v ^= (1 << i);
          }
        }
        ans += (__builtin_popcount(u) % 2 == 0 ? +1 : -1) * sub[v];
      }
      cout << ans << "\n";
    } else {
      int u = 0;
      for (int i = 0; i < L; ++i) {
        if (T[i] == '?') {
          u ^= (1 << i);
        }
      }
      int ans = 0;
      auto add = [&](int s) {
        int v = 0;
        for (int i = 0; i < L; ++i) {
          if (T[i] == '?') {
            if (s >> i & 1) {
              v ^= (1 << i);
            } else {
              
            }
          } else if (T[i] == '0') {
            
          } else {
            v ^= (1 << i);
          }
        }
        ans += S[v] - '0';
      };
      for (int s = u; s > 0; s = (s - 1) & u) {
        add(s);
      }
      add(0);
      cout << ans << "\n";
    }
  }

  return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int i = 0; i < S.size(); ++i) {
      |                   ~~^~~~~~~~~~
snake_escaping.cpp:41:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for (int i = 0; i < S.size(); ++i) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 135 ms 9900 KB Output is correct
12 Correct 141 ms 9692 KB Output is correct
13 Correct 163 ms 8892 KB Output is correct
14 Correct 226 ms 9012 KB Output is correct
15 Correct 169 ms 10068 KB Output is correct
16 Correct 224 ms 9052 KB Output is correct
17 Correct 208 ms 9044 KB Output is correct
18 Correct 98 ms 11052 KB Output is correct
19 Correct 110 ms 8020 KB Output is correct
20 Correct 115 ms 9524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 135 ms 9900 KB Output is correct
12 Correct 141 ms 9692 KB Output is correct
13 Correct 163 ms 8892 KB Output is correct
14 Correct 226 ms 9012 KB Output is correct
15 Correct 169 ms 10068 KB Output is correct
16 Correct 224 ms 9052 KB Output is correct
17 Correct 208 ms 9044 KB Output is correct
18 Correct 98 ms 11052 KB Output is correct
19 Correct 110 ms 8020 KB Output is correct
20 Correct 115 ms 9524 KB Output is correct
21 Correct 127 ms 11600 KB Output is correct
22 Correct 207 ms 11780 KB Output is correct
23 Correct 427 ms 10696 KB Output is correct
24 Correct 739 ms 10468 KB Output is correct
25 Correct 393 ms 12876 KB Output is correct
26 Correct 726 ms 10984 KB Output is correct
27 Correct 496 ms 10968 KB Output is correct
28 Correct 113 ms 13648 KB Output is correct
29 Correct 112 ms 9636 KB Output is correct
30 Correct 117 ms 11884 KB Output is correct
31 Correct 407 ms 11564 KB Output is correct
32 Correct 757 ms 11604 KB Output is correct
33 Correct 319 ms 10516 KB Output is correct
34 Correct 577 ms 10464 KB Output is correct
35 Correct 468 ms 11088 KB Output is correct
36 Correct 99 ms 9560 KB Output is correct
37 Correct 113 ms 11524 KB Output is correct
38 Correct 248 ms 9780 KB Output is correct
39 Correct 402 ms 10724 KB Output is correct
40 Correct 724 ms 10480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 38 ms 11248 KB Output is correct
12 Correct 39 ms 11252 KB Output is correct
13 Correct 86 ms 11248 KB Output is correct
14 Correct 167 ms 11220 KB Output is correct
15 Correct 73 ms 11356 KB Output is correct
16 Correct 179 ms 11256 KB Output is correct
17 Correct 107 ms 11252 KB Output is correct
18 Correct 33 ms 11504 KB Output is correct
19 Correct 32 ms 11168 KB Output is correct
20 Correct 31 ms 11256 KB Output is correct
21 Correct 96 ms 11256 KB Output is correct
22 Correct 182 ms 11248 KB Output is correct
23 Correct 75 ms 11248 KB Output is correct
24 Correct 130 ms 11248 KB Output is correct
25 Correct 114 ms 11216 KB Output is correct
26 Correct 31 ms 11024 KB Output is correct
27 Correct 31 ms 11252 KB Output is correct
28 Correct 44 ms 11184 KB Output is correct
29 Correct 101 ms 11252 KB Output is correct
30 Correct 165 ms 11252 KB Output is correct
31 Correct 65 ms 11108 KB Output is correct
32 Correct 149 ms 11180 KB Output is correct
33 Correct 113 ms 11240 KB Output is correct
34 Correct 34 ms 10996 KB Output is correct
35 Correct 88 ms 11248 KB Output is correct
36 Correct 85 ms 11248 KB Output is correct
37 Correct 87 ms 11176 KB Output is correct
38 Correct 98 ms 11300 KB Output is correct
39 Correct 85 ms 11248 KB Output is correct
40 Correct 85 ms 11252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 135 ms 9900 KB Output is correct
12 Correct 141 ms 9692 KB Output is correct
13 Correct 163 ms 8892 KB Output is correct
14 Correct 226 ms 9012 KB Output is correct
15 Correct 169 ms 10068 KB Output is correct
16 Correct 224 ms 9052 KB Output is correct
17 Correct 208 ms 9044 KB Output is correct
18 Correct 98 ms 11052 KB Output is correct
19 Correct 110 ms 8020 KB Output is correct
20 Correct 115 ms 9524 KB Output is correct
21 Correct 127 ms 11600 KB Output is correct
22 Correct 207 ms 11780 KB Output is correct
23 Correct 427 ms 10696 KB Output is correct
24 Correct 739 ms 10468 KB Output is correct
25 Correct 393 ms 12876 KB Output is correct
26 Correct 726 ms 10984 KB Output is correct
27 Correct 496 ms 10968 KB Output is correct
28 Correct 113 ms 13648 KB Output is correct
29 Correct 112 ms 9636 KB Output is correct
30 Correct 117 ms 11884 KB Output is correct
31 Correct 407 ms 11564 KB Output is correct
32 Correct 757 ms 11604 KB Output is correct
33 Correct 319 ms 10516 KB Output is correct
34 Correct 577 ms 10464 KB Output is correct
35 Correct 468 ms 11088 KB Output is correct
36 Correct 99 ms 9560 KB Output is correct
37 Correct 113 ms 11524 KB Output is correct
38 Correct 248 ms 9780 KB Output is correct
39 Correct 402 ms 10724 KB Output is correct
40 Correct 724 ms 10480 KB Output is correct
41 Correct 38 ms 11248 KB Output is correct
42 Correct 39 ms 11252 KB Output is correct
43 Correct 86 ms 11248 KB Output is correct
44 Correct 167 ms 11220 KB Output is correct
45 Correct 73 ms 11356 KB Output is correct
46 Correct 179 ms 11256 KB Output is correct
47 Correct 107 ms 11252 KB Output is correct
48 Correct 33 ms 11504 KB Output is correct
49 Correct 32 ms 11168 KB Output is correct
50 Correct 31 ms 11256 KB Output is correct
51 Correct 96 ms 11256 KB Output is correct
52 Correct 182 ms 11248 KB Output is correct
53 Correct 75 ms 11248 KB Output is correct
54 Correct 130 ms 11248 KB Output is correct
55 Correct 114 ms 11216 KB Output is correct
56 Correct 31 ms 11024 KB Output is correct
57 Correct 31 ms 11252 KB Output is correct
58 Correct 44 ms 11184 KB Output is correct
59 Correct 101 ms 11252 KB Output is correct
60 Correct 165 ms 11252 KB Output is correct
61 Correct 65 ms 11108 KB Output is correct
62 Correct 149 ms 11180 KB Output is correct
63 Correct 113 ms 11240 KB Output is correct
64 Correct 34 ms 10996 KB Output is correct
65 Correct 88 ms 11248 KB Output is correct
66 Correct 85 ms 11248 KB Output is correct
67 Correct 87 ms 11176 KB Output is correct
68 Correct 98 ms 11300 KB Output is correct
69 Correct 85 ms 11248 KB Output is correct
70 Correct 85 ms 11252 KB Output is correct
71 Correct 161 ms 25844 KB Output is correct
72 Correct 300 ms 25840 KB Output is correct
73 Correct 1265 ms 24468 KB Output is correct
74 Execution timed out 2060 ms 22576 KB Time limit exceeded
75 Halted 0 ms 0 KB -