結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
Konton7
|
| 提出日時 | 2019-05-19 22:22:25 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 2,000 ms |
| コード長 | 1,151 bytes |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-09-17 06:33:46 |
| 合計ジャッジ時間 | 1,483 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
w, h = [ int(v) for v in input().split() ]
cave = [ list(input()) for i in range(h) ]
path_list = []
for i in range(h):
for j in range(w):
if cave[i][j] == ".":
path_list.append((i,j))
def search():
global path_list
outlist = [path_list[0]]
que = [path_list[0]]
while que != []:
y, x = que[0][0], que[0][1]
if (y, x+1) in path_list and (y, x+1) not in outlist:
outlist.append((y, x+1))
que.append((y, x+1))
if (y, x-1) in path_list and (y, x-1) not in outlist:
outlist.append((y, x-1))
que.append((y, x-1))
if (y+1, x) in path_list and (y+1, x) not in outlist:
outlist.append((y+1, x))
que.append((y+1, x))
if (y-1, x) in path_list and (y-1, x) not in outlist:
outlist.append((y-1, x))
que.append((y-1, x))
del que[0]
return outlist
path1 = sorted(search())
path2 = sorted([ i for i in path_list if i not in path1 ])
d = w*h
for i in path1:
for j in path2:
dij = abs(i[0]-j[0]) + abs(i[1]-j[1])
d = min(dij,d)
print(d-1)
Konton7