結果
| 問題 |
No.2897 2集合間距離
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2024-11-13 15:43:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 133 ms / 3,500 ms |
| コード長 | 1,060 bytes |
| コンパイル時間 | 2,141 ms |
| コンパイル使用メモリ | 204,780 KB |
| 最終ジャッジ日時 | 2025-02-25 04:05:20 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/modint>
using namespace std;
//using namespace atcoder;
using ll = long long;
//using mint = modint998244353;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int N, x, y, ans=1e9;
cin >> N;
queue<pair<int, int>> que;
vector dist(1000, vector<int>(1000, 1e9));
for (int i=0; i<N; i++){
cin >> x >> y;
dist[x][y] = 0;
que.push({x, y});
}
auto f=[&](int i, int j){
return 0<=i && i<1000 && 0<=j && j<1000;
};
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
while(!que.empty()){
tie(x, y) = que.front();
que.pop();
for (int i=0; i<4; i++){
int nx=x+dx[i], ny=y+dy[i];
if (f(nx, ny) && dist[nx][ny] == 1e9){
dist[nx][ny] = dist[x][y]+1;
que.push({nx, ny});
}
}
}
cin >> N;
for (int i=0; i<N; i++){
cin >> x >> y;
ans = min(ans, dist[x][y]);
}
cout << ans << endl;
return 0;
}
srjywrdnprkt