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;
typedef long long ll;
#define fi first
#define se second
#define dot cerr << "passed" << '\n';
#define debug(x) cerr << "debug : " << #x << " = " << x << '\n';
ll N, Q;
pair<ll, ll> A[100007];
struct query {
ll t, id;
};
query Queries[500007];
ll ans[500007];
namespace subtask1 {
ll Cnt[57], cell[2][507][507];
const ll offset = 157;
void solve() {
for(int i = 1; i <= N; ++i) {
cell[0][A[i].fi + offset][A[i].se + offset] = 1;
}
auto fill = [&](ll p, ll a, ll b, ll c, ll d) {
if (cell[p][c][d] == -1) return; // grey can't fill
if (cell[p][c][d] == 1) return; // black can't fill
cell[(p + 1) % 2][c][d] = 1; // white near black -> fill
};
// dot;
for(int tm = 0; tm <= 500; ++tm) { // tm fix
memset(cell[(tm + 1) % 2], 0, sizeof(cell[(tm + 1) % 2]));
for(int i = 1; i <= 500; ++i) {
for(int j = 1; j <= 500; ++j) {
// 1 : black
// -1 : grey
// 0 : white
if (cell[tm % 2][i][j] == 1) {
Cnt[tm]++;
fill(tm % 2, i, j, i - 1, j);
fill(tm % 2, i, j, i, j - 1);
fill(tm % 2, i, j, i + 1, j);
fill(tm % 2, i, j, i, j + 1);
cell[(tm + 1) % 2][i][j] = -1; // its grey now
}
}
}
// cerr << "print table " << '\n';
// for(int i = -5 + offset; i <= 5 + offset; ++i) {
// for(int j = -5 + offset; j <= 5 + offset; ++j) {
// if (cell[tm % 2][i][j] == -1) cerr << 2;
// else cerr << cell[tm % 2][i][j];
// }
// cerr << '\n';
// }
// cerr << '\n';
}
for(int i = 1; i <= Q; ++i) {
// cerr << "query " << i << '\n';
cout << Cnt[Queries[i].t] << '\n';
}
}
void process() {
solve();
}
}
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0); cerr.tie(0);
if (fopen("FILE.INP", "r")) {
freopen("FILE.INP", "r", stdin);
freopen("FILE.OUT", "w", stdout);
}
cin >> N >> Q;
for(int i = 1; i <= N; ++i) cin >> A[i].fi >> A[i].se;
for(int i = 1; i <= Q; ++i) {
cin >> Queries[i].t;
Queries[i].id = i;
}
subtask1 :: process();
}
Compilation message (stderr)
cell.cpp: In function 'int main()':
cell.cpp:73:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen("FILE.INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cell.cpp:74:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen("FILE.OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |