結果
問題 |
No.2897 2集合間距離
|
ユーザー |
![]() |
提出日時 | 2024-09-25 15:21:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 926 bytes |
コンパイル時間 | 1,867 ms |
コンパイル使用メモリ | 197,276 KB |
最終ジャッジ日時 | 2025-02-24 12:10:44 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 WA * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int N = 2e5 + 10, M = 1e3 + 10; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; int n, x[N], y[N], m, z[N], w[N], d[M][M], ans = 2 * M; queue<pii> que; void Record(int x, int y, int dis) { if (x < 0 || x >= M || y < 0 || y >= M || d[x][y]) return ; d[x][y] = dis, que.push({x, y}); } void bfs() { for (int i = 1; i <= n; i++) Record(x[i], y[i], 1); while (!que.empty()) { auto [x, y] = que.front(); que.pop(); for (int i = 0; i < 4; i++) Record(x + dx[i], y + dy[i], d[x][y] + 1); } } int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; cin >> m; for (int i = 1; i <= n; i++) cin >> z[i] >> w[i]; bfs(); for (int i = 1; i <= m; i++) ans = min(ans, d[z[i]][w[i]] - 1); cout << ans; return 0; }