Submission #890114

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

using namespace std;

const int L = 20;

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

string s;

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

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

  int tm = (tl + tr) / 2;
  construct(2 * v, tl, tm, d + 1);
  construct(2 * v + 1, tm + 1, tr, d + 1);
  for (int i = 0; i < 3; ++i) {
    if (!need[d][i]) {
      continue;
    }
    for (int 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);

  int l, q;
  cin >> l >> q;
  cin >> s;

  vector<int> queries;
  while (q--) {
    string sq;
    cin >> sq;
    int x = 0;
    for (int 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, (1 << l) - 1, 0);
  for (auto &i : queries) {
    cout << seg[1].x[i] << "\n";
  }
}

Compilation message

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