Submission #890111

# Submission time Handle Problem Language Result Execution time Memory
890111 2023-12-20T14:45:29 Z avighna Snake Escaping (JOI18_snake_escaping) C++17
0 / 100
16 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll L = 20;

class Node {
public:
  map<ll, ll> x;
};

string s;

Node seg[1LL << (L + 2)];
bool need[L][3];

void construct(ll v, ll tl, ll tr, ll d) {
  if (tl == tr) {
    seg[v].x[0] = s[tl] - '0';
    return;
  }

  ll tm = (tl + tr) / 2;
  construct(2 * v, tl, tm, d + 1);
  construct(2 * v + 1, tm + 1, tr, d + 1);
  for (ll i = 0; i < 3; ++i) {
    if (!need[d][i]) {
      continue;
    }
    for (ll j = 0; j < seg[2 * v].x.size(); ++j) {
      if (i == 0) {
        seg[v].x[3 * j + i] = seg[2 * v].x[j];
      } else if (i == 1) {
        seg[v].x[3 * j + i] = seg[2 * v + 1].x[j];
      } else {
        seg[v].x[3 * j + i] = seg[2 * v].x[j] + seg[2 * v + 1].x[j];
      }
    }
  }
  seg[2 * v].x.clear();
  seg[2 * v + 1].x.clear();
}

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

  ll l, q;
  cin >> l >> q;
  cin >> s;

  vector<ll> queries;
  while (q--) {
    string sq;
    cin >> sq;
    ll x = 0;
    for (ll i = sq.length() - 1; i >= 0; --i) {
      char c = sq[i];
      if (c == '?') {
        c = '2';
      }
      x = 3 * x + (c - '0');
      need[i][c - '0'] = true;
    }
    queries.push_back(x);
  }

  construct(1, 0, (1LL << l) - 1, 0);
  for (auto &i : queries) {
    cout << seg[1].x[i] << "\n";
  }
}

Compilation message

snake_escaping.cpp: In function 'void construct(long long int, long long int, long long int, long long int)':
snake_escaping.cpp:32:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (ll j = 0; j < seg[2 * v].x.size(); ++j) {
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -