#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
using vi = vector<int>;
struct State {
int t = 0;
set<pi> black, gray;
State() {};
State(vi &x, vi &y) {
for (int i = 0; i < x.size(); i++) black.insert({x[i], y[i]});
}
State(int T, set<pi> &B, set<pi> &G) {
t = T; black = B; gray = G;
}
State next() {
set<pi> ng = black, nb;
for (auto el : black) {
for (auto d : vector<pi>({{0, -1}, {0, 1}, {-1, 0}, {1, 0}})) {
pi nx = {el.first + d.first, el.second + d.second};
if (!black.count(nx) && !gray.count(nx)) nb.insert(nx);
}
}
return State(t+1, nb, ng);
}
void output(int M = -1) {
if (M == -1) {
for (auto el : black) M = max({M, abs(el.first), abs(el.second)});
for (auto el : gray) M = max({M, abs(el.first), abs(el.second)});
}
for (int i = -M; i <= M; i++) {
for (int j = -M; j <= M; j++) {
if (black.count({i, j})) cout << 1;
else if (gray.count({i, j})) cout << 2;
else cout << 0;
cout << " ";
}
cout << "\n";
}
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, q; cin >> n >> q;
vector<int> x(n), y(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
auto cur = State(y, x);
vector<int> ans(1, n);
cur = cur.next(); ans.push_back(cur.black.size());
cur = cur.next(); ans.push_back(cur.black.size());
while (!(ans[ans.size() - 1] - ans[ans.size() - 2] == 4 && ans[ans.size() - 2] - ans[ans.size() - 3] == 4)) {
cur = cur.next();
ans.push_back(cur.black.size());
}
while (q--) {
int t; cin >> t;
if (t < ans.size()) cout << ans[t] << "\n";
else cout << ans.back() + 4 * (t - ans.size() + 1) << "\n";
}
return 0;
}
| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |