結果

問題 No.157 2つの空洞
ユーザー ktshunktshun
提出日時 2015-06-09 13:48:03
言語 Python2
(2.7.18)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 752 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 6,716 KB
実行使用メモリ 6,328 KB
最終ジャッジ日時 2023-09-20 20:22:26
合計ジャッジ時間 1,275 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,072 KB
testcase_01 AC 12 ms
6,308 KB
testcase_02 AC 12 ms
6,244 KB
testcase_03 AC 12 ms
6,060 KB
testcase_04 AC 12 ms
6,096 KB
testcase_05 AC 13 ms
6,152 KB
testcase_06 AC 12 ms
6,148 KB
testcase_07 AC 12 ms
6,144 KB
testcase_08 AC 12 ms
6,092 KB
testcase_09 AC 12 ms
6,100 KB
testcase_10 AC 12 ms
6,072 KB
testcase_11 AC 12 ms
6,328 KB
testcase_12 AC 13 ms
6,148 KB
testcase_13 AC 12 ms
6,100 KB
testcase_14 AC 13 ms
6,280 KB
testcase_15 AC 12 ms
6,220 KB
testcase_16 AC 13 ms
6,176 KB
testcase_17 AC 13 ms
6,172 KB
testcase_18 AC 12 ms
6,168 KB
testcase_19 AC 12 ms
6,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding:utf-8 -*-
from heapq import heappop, heappush

if __name__ == "__main__":
	w,h = map(int,raw_input().split())
	c = [raw_input()for i in range(h)]
	arrived = [[False for i in xrange(w)]for j in xrange(h)]
	direc = [(1,0),(-1,0),(0,1),(0,-1)]
	for i in xrange(h):
		for j in range(w):
			if c[i][j] == ".":
				hp = []
				heappush(hp,(0,i,j))
				arrived[i][j] = True
				while len (hp) != 0:
					(d,a,b) = heappop(hp)
					if d > 0 and c[a][b] == ".":
						print d
						exit()
					for da,db in direc:
						na = a + da
						nb = b + db
						nd = d
						if na >= 0 and nb >= 0 and na < h and nb < w and arrived[na][nb] == False:
							if c[na][nb] == "#":
								nd += 1
							arrived[na][nb] = True
							heappush(hp,(nd,na,nb))
0