| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 890104 | avighna | Snake Escaping (JOI18_snake_escaping) | C++17 | 21 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;
#define ll long long
const ll L = 20;
class Node {
public:
vector<ll> x;
};
string s;
Node seg[4 * (1 << L)];
void construct(ll v, ll tl, ll tr) {
if (tl == tr) {
seg[v].x.resize(1);
seg[v].x[0] = s[tl] - '0';
return;
}
ll tm = (tl + tr) / 2;
construct(2 * v, tl, tm);
construct(2 * v + 1, tm + 1, tr);
seg[v].x.resize(seg[2 * v].x.size() * 3);
for (ll i = 0; i < 3; ++i) {
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];
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll l, q;
cin >> l >> q;
cin >> s;
construct(1, 0, (1LL << l) - 1);
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');
}
cout << seg[1].x[x] << "\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... | ||||
