이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |