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>
#define N 4005
using namespace std;
int d[N][N];
const int add = 2000;
int x[100005],y[100005];
int cnt[N];
void solve(){
int n,q;
cin >> n >> q;
memset(d,-1,sizeof d);
queue<pair<int,int>> qq;
for(int i =1;i<=n;i++){
cin >> x[i] >> y[i];
x[i] += add;
y[i] += add;
d[x[i]][y[i]] = 0;
qq.push({x[i],y[i]});
}
while(qq.size()){
auto tp = qq.front();
qq.pop();
auto [x,y] = tp;
if(d[x][y] >= 1005)
break;
cnt[d[x][y]]++;
for(int dx = -1;dx <=1;dx++){
for(int dy = -1;dy<=1;dy++){
if(abs(dx) + abs(dy) != 1)
continue;
if(d[x + dx][y + dy] == -1){
d[x + dx][y + dy] = d[x][y] + 1;
qq.push({x+dx,y+dy});
}
}
}
}
while(q--){
int t;
cin >> t;
cout << cnt[t] << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# | 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... |