# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
890114 | avighna | Snake Escaping (JOI18_snake_escaping) | C++17 | 12 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |