結果

問題 No.157 2つの空洞
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-28 03:02:55
言語 Python2
(2.7.18)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 6,668 KB
実行使用メモリ 6,340 KB
最終ジャッジ日時 2023-09-06 03:56:19
合計ジャッジ時間 1,549 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,172 KB
testcase_01 AC 12 ms
6,092 KB
testcase_02 AC 11 ms
6,120 KB
testcase_03 AC 11 ms
6,204 KB
testcase_04 AC 12 ms
6,124 KB
testcase_05 AC 11 ms
6,336 KB
testcase_06 AC 11 ms
6,224 KB
testcase_07 AC 11 ms
6,124 KB
testcase_08 AC 12 ms
6,088 KB
testcase_09 AC 12 ms
6,208 KB
testcase_10 AC 12 ms
6,216 KB
testcase_11 AC 12 ms
6,188 KB
testcase_12 AC 14 ms
6,092 KB
testcase_13 AC 12 ms
6,284 KB
testcase_14 AC 13 ms
6,340 KB
testcase_15 AC 12 ms
6,172 KB
testcase_16 AC 13 ms
6,100 KB
testcase_17 AC 13 ms
6,300 KB
testcase_18 AC 12 ms
6,096 KB
testcase_19 AC 13 ms
6,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
W,H=map(int,raw_input().split())
C=[raw_input() for i in range(H)]
arrived=[[False for i in range(W)] for j in range(H)]
directions=[(1,0),(-1,0),(0,1),(0,-1)]
for i in range(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 directions:
                    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