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 all(x) x.begin(),x.end();
#define LCBorz ios_base::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
const int C=2002;
const int N=C<<1|1;
const int INF=1e9;
const int lim=1000;
vector<int> dx={-1,0,1,0},dy={0,1,0,-1};
int dis[N][N],ans[N];
int32_t main(){
LCBorz;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
dis[i][j]=INF;
}
}
int n,q1;cin>>n>>q1;
queue<pair<int,int>> q;
for(int i=0;i<n;i++){
int a,b;cin>>a>>b;
dis[a+C][b+C]=0;
q.push({a+C,b+C});
}
while(q.size()){
auto [a,b]=q.front();
q.pop();
if(dis[a][b]>lim)continue;
ans[dis[a][b]]++;
for(int k=0;k<4;k++){
int c=a+dx[k];
int d=b+dy[k];
if(dis[c][d]==INF){
dis[c][d]=dis[a][b]+1;
q.push({c,d});
}
}
}
for(int i=0;i<q1;i++){
int t;cin>>t;
cout<<ans[t]<<endl;
}
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... |