結果
問題 | No.2897 2集合間距離 |
ユーザー | 2000 Ekiben |
提出日時 | 2024-09-20 22:52:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,123 ms / 3,500 ms |
コード長 | 712 bytes |
コンパイル時間 | 197 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 197,000 KB |
最終ジャッジ日時 | 2024-09-20 22:53:16 |
合計ジャッジ時間 | 18,222 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 388 ms
126,252 KB |
testcase_01 | AC | 383 ms
126,336 KB |
testcase_02 | AC | 409 ms
125,952 KB |
testcase_03 | AC | 446 ms
127,232 KB |
testcase_04 | AC | 459 ms
127,400 KB |
testcase_05 | AC | 488 ms
127,360 KB |
testcase_06 | AC | 460 ms
127,616 KB |
testcase_07 | AC | 442 ms
127,488 KB |
testcase_08 | AC | 504 ms
127,488 KB |
testcase_09 | AC | 446 ms
128,000 KB |
testcase_10 | AC | 486 ms
130,944 KB |
testcase_11 | AC | 537 ms
133,348 KB |
testcase_12 | AC | 604 ms
141,568 KB |
testcase_13 | AC | 688 ms
143,744 KB |
testcase_14 | AC | 721 ms
158,720 KB |
testcase_15 | AC | 823 ms
169,728 KB |
testcase_16 | AC | 1,114 ms
196,864 KB |
testcase_17 | AC | 1,101 ms
196,604 KB |
testcase_18 | AC | 1,114 ms
196,736 KB |
testcase_19 | AC | 1,059 ms
196,864 KB |
testcase_20 | AC | 1,123 ms
197,000 KB |
testcase_21 | AC | 921 ms
173,568 KB |
testcase_22 | AC | 842 ms
166,272 KB |
testcase_23 | AC | 964 ms
173,184 KB |
ソースコード
from collections import deque N = int(input()) S = [tuple(map(int, input().split())) for _ in range(N)] M = int(input()) T = [tuple(map(int, input().split())) for _ in range(M)] G, I = 1000, float('inf') dS, dT = [[I]*G for _ in range(G)], [[I]*G for _ in range(G)] qS, qT = deque(S), deque(T) for x, y in S: dS[x][y] = 0 for x, y in T: dT[x][y] = 0 def bfs(q, d): while q: x, y = q.popleft() for dx, dy in [(-1,0), (1,0), (0,-1), (0,1)]: nx, ny = x+dx, y+dy if 0<=nx<G and 0<=ny<G and d[nx][ny]==I: d[nx][ny] = d[x][y] + 1 q.append((nx, ny)) bfs(qS, dS) bfs(qT, dT) print(min(dS[x][y] + dT[x][y] for x in range(G) for y in range(G)))