結果

問題 No.697 池の数はいくつか
ユーザー 👑 KazunKazun
提出日時 2020-06-03 00:05:03
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,059 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 308,368 KB
最終ジャッジ日時 2024-05-04 06:59:02
合計ジャッジ時間 10,481 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,144 KB
testcase_01 AC 44 ms
53,632 KB
testcase_02 AC 44 ms
53,632 KB
testcase_03 AC 44 ms
53,632 KB
testcase_04 AC 45 ms
53,888 KB
testcase_05 AC 44 ms
54,144 KB
testcase_06 AC 44 ms
53,504 KB
testcase_07 AC 45 ms
54,272 KB
testcase_08 AC 45 ms
53,888 KB
testcase_09 AC 45 ms
53,504 KB
testcase_10 AC 45 ms
53,888 KB
testcase_11 AC 45 ms
53,888 KB
testcase_12 AC 45 ms
53,760 KB
testcase_13 AC 46 ms
53,888 KB
testcase_14 AC 46 ms
53,680 KB
testcase_15 AC 44 ms
54,392 KB
testcase_16 AC 44 ms
53,760 KB
testcase_17 AC 47 ms
53,504 KB
testcase_18 AC 44 ms
53,888 KB
testcase_19 AC 45 ms
53,760 KB
testcase_20 AC 45 ms
53,888 KB
testcase_21 AC 46 ms
53,504 KB
testcase_22 AC 46 ms
54,144 KB
testcase_23 AC 46 ms
53,504 KB
testcase_24 MLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

H,W=map(int,input().split())

def f(x,y):
    return y*(W+2)+x

def g(n):
    return (n%(W+2),n//(W+2))

def BFS(V):
    Q=deque([V[0]])
    S={v:False for v in V}
    S[V[0]]=True
    T=[V[0]]
    U=set(V)
    
    while Q:
        v=Q.popleft()

        N=[]
        if v+1 in U and not S[v+1]:
            Q.append(v+1)
            T.append(v+1)
            S[v+1]=True
            
        if v-1 in U  and not S[v-1]:
            Q.append(v-1)
            T.append(v-1)
            S[v-1]=True
            
        if v+(W+2) in U  and not S[v+(W+2)]:
            Q.append(v+(W+2))
            T.append(v+(W+2))
            S[v+(W+2)]=True
            
        if v-(W+2) in U  and not S[v-(W+2)]:
            Q.append(v-(W+2))
            T.append(v-(W+2))
            S[v-(W+2)]=True

    return T

V=set()
for y in range(H):
    A=list(map(int,input().split()))
    for x in range(W):
        if A[x]==1:
            V.add(f(x+1,y+1))

U=set()
X=set(V)
k=0
while U!=X:
    k+=1
    U|=set(BFS(list(X-U)))

print(k)
    
0