Submission #965392

# Submission time Handle Problem Language Result Execution time Memory
965392 2024-04-18T12:32:17 Z four_specks Snake Escaping (JOI18_snake_escaping) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

namespace {}

void solve() {
  int h, q;
  cin >> h >> q;
  uint32_t n = 1 << h;
  string a;
  cin >> a;
  vector dp_sub(n, vector<int>(h + 1)), dp_super(n, vector<int>(h + 1));
  for (uint32_t x = 0; x < n; x++) {
    dp_sub[x][0] = a[x] - '0';
    for (int s = 0; s < h; s++) {
      dp_sub[x][s + 1] = dp_sub[x][s];
      if (x >> s & 1) {
        dp_sub[x][s + 1] += dp_sub[x ^ (1u << s)][s];
      }
    }
  }
  for (uint32_t x = n - 1; x + 1 > 0; x--) {
    dp_super[x][0] = a[x] - '0';
    for (int s = 0; s < h; s++) {
      dp_super[x][s + 1] = dp_super[x][s];
      if (!(x >> s & 1)) {
        dp_super[x][s + 1] += dp_super[x | (1u << s)][s];
      }
    }
  }
  for (int i = 0; i < q; i++) {
    string t;
    cin >> t;
    ranges::reverse(t);
    array<uint32_t, 3> v;
    v.fill(0);
    for (int s = 0; s < h; s++) {
      if (t[s] == '0') {
        v[0] |= 1u << s;
      } else if (t[s] == '1') {
        v[1] |= 1u << s;
      } else {
        v[2] |= 1u << s;
      }
    }
    int ans = 0;
    {
      vector<int> cnt;
      ranges::transform(v, back_inserter(cnt), popcount<uint32_t>);
      int p = ranges::distance(cnt.begin(), ranges::min_element(cnt));
      for (uint32_t x = v[p];; x = (x - 1) & v[p]) {
        if (p == 2) {
          ans += a[v[1] | x] - '0';
        } else {
          int term = p == 1 ? dp_sub[(v[1] ^ x) | v[2]][h] : dp_super[v[1] | x][h];
          if (popcount(x) % 2 == 0) {
            ans += term;
          } else {
            ans -= term;
          }
        }
        if (x == 0) {
          break;
        }
      }
    }
    cout << ans << '\n';
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  solve();

  return 0;
}

Compilation message

snake_escaping.cpp: In function 'void solve()':
snake_escaping.cpp:35:5: error: 'ranges' has not been declared
   35 |     ranges::reverse(t);
      |     ^~~~~~
snake_escaping.cpp:50:7: error: 'ranges' has not been declared
   50 |       ranges::transform(v, back_inserter(cnt), popcount<uint32_t>);
      |       ^~~~~~
snake_escaping.cpp:50:48: error: 'popcount' was not declared in this scope
   50 |       ranges::transform(v, back_inserter(cnt), popcount<uint32_t>);
      |                                                ^~~~~~~~
snake_escaping.cpp:50:65: error: expected primary-expression before '>' token
   50 |       ranges::transform(v, back_inserter(cnt), popcount<uint32_t>);
      |                                                                 ^
snake_escaping.cpp:50:66: error: expected primary-expression before ')' token
   50 |       ranges::transform(v, back_inserter(cnt), popcount<uint32_t>);
      |                                                                  ^
snake_escaping.cpp:51:15: error: 'ranges' has not been declared
   51 |       int p = ranges::distance(cnt.begin(), ranges::min_element(cnt));
      |               ^~~~~~
snake_escaping.cpp:51:45: error: 'ranges' has not been declared
   51 |       int p = ranges::distance(cnt.begin(), ranges::min_element(cnt));
      |                                             ^~~~~~