#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
int N, Q, X[100005], Y[100005], dist[2005][2005], dr[] = {-1, 0, 0, 1}, dc[] = {0, -1, 1, 0}, ans[4000005];
queue<ii> qu;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> Q;
for (int i = 1; i <= 2001; i++) {
for (int j = 1; j <= 2001; j++) {
dist[i][j] = (int)1e9;
}
}
for (int i = 1; i <= N; i++) {
cin >> X[i] >> Y[i];
X[i] += 1001;
Y[i] += 1001;
dist[X[i]][Y[i]] = 0;
qu.emplace(X[i], Y[i]);
}
while (!qu.empty()) {
auto [r, c] = qu.front();
qu.pop();
for (int k = 0; k < 4; k++) {
int nr = r + dr[k], nc = c + dc[k];
if (1 <= nr && nr <= 2001 && 1 <= nc && nc <= 2001) {
if (dist[nr][nc] > dist[r][c] + 1) {
dist[nr][nc] = dist[r][c] + 1;
qu.emplace(nr, nc);
}
}
}
}
for (int i = 1; i <= 2001; i++) {
for (int j = 1; j <= 2001; j++) {
ans[dist[i][j]]++;
}
}
for (int i = 1, t; i <= Q; i++) {
cin >> t;
cout << ans[t] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
16064 KB |
Output is correct |
2 |
Correct |
71 ms |
16076 KB |
Output is correct |
3 |
Correct |
86 ms |
16060 KB |
Output is correct |
4 |
Correct |
74 ms |
16076 KB |
Output is correct |
5 |
Correct |
78 ms |
16200 KB |
Output is correct |
6 |
Correct |
75 ms |
16052 KB |
Output is correct |
7 |
Correct |
73 ms |
15956 KB |
Output is correct |
8 |
Correct |
74 ms |
16212 KB |
Output is correct |
9 |
Correct |
71 ms |
16068 KB |
Output is correct |
10 |
Correct |
71 ms |
15968 KB |
Output is correct |
11 |
Correct |
77 ms |
16068 KB |
Output is correct |
12 |
Correct |
74 ms |
16076 KB |
Output is correct |
13 |
Correct |
71 ms |
16084 KB |
Output is correct |
14 |
Correct |
70 ms |
16084 KB |
Output is correct |
15 |
Correct |
70 ms |
16084 KB |
Output is correct |
16 |
Correct |
77 ms |
16068 KB |
Output is correct |
17 |
Correct |
83 ms |
16064 KB |
Output is correct |
18 |
Correct |
79 ms |
16076 KB |
Output is correct |
19 |
Correct |
73 ms |
15956 KB |
Output is correct |
20 |
Correct |
70 ms |
15956 KB |
Output is correct |
21 |
Correct |
76 ms |
16072 KB |
Output is correct |
22 |
Correct |
70 ms |
16056 KB |
Output is correct |
23 |
Correct |
80 ms |
16064 KB |
Output is correct |
24 |
Correct |
69 ms |
16060 KB |
Output is correct |
25 |
Correct |
71 ms |
16064 KB |
Output is correct |
26 |
Correct |
81 ms |
16072 KB |
Output is correct |
27 |
Correct |
78 ms |
16184 KB |
Output is correct |
28 |
Correct |
75 ms |
16060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
16064 KB |
Output is correct |
2 |
Correct |
71 ms |
16076 KB |
Output is correct |
3 |
Correct |
86 ms |
16060 KB |
Output is correct |
4 |
Correct |
74 ms |
16076 KB |
Output is correct |
5 |
Correct |
78 ms |
16200 KB |
Output is correct |
6 |
Correct |
75 ms |
16052 KB |
Output is correct |
7 |
Correct |
73 ms |
15956 KB |
Output is correct |
8 |
Correct |
74 ms |
16212 KB |
Output is correct |
9 |
Correct |
71 ms |
16068 KB |
Output is correct |
10 |
Correct |
71 ms |
15968 KB |
Output is correct |
11 |
Correct |
77 ms |
16068 KB |
Output is correct |
12 |
Correct |
74 ms |
16076 KB |
Output is correct |
13 |
Correct |
71 ms |
16084 KB |
Output is correct |
14 |
Correct |
70 ms |
16084 KB |
Output is correct |
15 |
Correct |
70 ms |
16084 KB |
Output is correct |
16 |
Correct |
77 ms |
16068 KB |
Output is correct |
17 |
Correct |
83 ms |
16064 KB |
Output is correct |
18 |
Correct |
79 ms |
16076 KB |
Output is correct |
19 |
Correct |
73 ms |
15956 KB |
Output is correct |
20 |
Correct |
70 ms |
15956 KB |
Output is correct |
21 |
Correct |
76 ms |
16072 KB |
Output is correct |
22 |
Correct |
70 ms |
16056 KB |
Output is correct |
23 |
Correct |
80 ms |
16064 KB |
Output is correct |
24 |
Correct |
69 ms |
16060 KB |
Output is correct |
25 |
Correct |
71 ms |
16064 KB |
Output is correct |
26 |
Correct |
81 ms |
16072 KB |
Output is correct |
27 |
Correct |
78 ms |
16184 KB |
Output is correct |
28 |
Correct |
75 ms |
16060 KB |
Output is correct |
29 |
Incorrect |
68 ms |
16072 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
21 ms |
32268 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
21 ms |
32268 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
32296 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
32296 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
16064 KB |
Output is correct |
2 |
Correct |
71 ms |
16076 KB |
Output is correct |
3 |
Correct |
86 ms |
16060 KB |
Output is correct |
4 |
Correct |
74 ms |
16076 KB |
Output is correct |
5 |
Correct |
78 ms |
16200 KB |
Output is correct |
6 |
Correct |
75 ms |
16052 KB |
Output is correct |
7 |
Correct |
73 ms |
15956 KB |
Output is correct |
8 |
Correct |
74 ms |
16212 KB |
Output is correct |
9 |
Correct |
71 ms |
16068 KB |
Output is correct |
10 |
Correct |
71 ms |
15968 KB |
Output is correct |
11 |
Correct |
77 ms |
16068 KB |
Output is correct |
12 |
Correct |
74 ms |
16076 KB |
Output is correct |
13 |
Correct |
71 ms |
16084 KB |
Output is correct |
14 |
Correct |
70 ms |
16084 KB |
Output is correct |
15 |
Correct |
70 ms |
16084 KB |
Output is correct |
16 |
Correct |
77 ms |
16068 KB |
Output is correct |
17 |
Correct |
83 ms |
16064 KB |
Output is correct |
18 |
Correct |
79 ms |
16076 KB |
Output is correct |
19 |
Correct |
73 ms |
15956 KB |
Output is correct |
20 |
Correct |
70 ms |
15956 KB |
Output is correct |
21 |
Correct |
76 ms |
16072 KB |
Output is correct |
22 |
Correct |
70 ms |
16056 KB |
Output is correct |
23 |
Correct |
80 ms |
16064 KB |
Output is correct |
24 |
Correct |
69 ms |
16060 KB |
Output is correct |
25 |
Correct |
71 ms |
16064 KB |
Output is correct |
26 |
Correct |
81 ms |
16072 KB |
Output is correct |
27 |
Correct |
78 ms |
16184 KB |
Output is correct |
28 |
Correct |
75 ms |
16060 KB |
Output is correct |
29 |
Incorrect |
68 ms |
16072 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |