結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,576 KB
testcase_01 AC 41 ms
54,084 KB
testcase_02 AC 41 ms
54,048 KB
testcase_03 AC 41 ms
54,776 KB
testcase_04 AC 41 ms
54,856 KB
testcase_05 AC 41 ms
55,704 KB
testcase_06 AC 42 ms
55,160 KB
testcase_07 AC 42 ms
54,088 KB
testcase_08 AC 42 ms
53,604 KB
testcase_09 AC 41 ms
54,988 KB
testcase_10 AC 41 ms
54,996 KB
testcase_11 AC 41 ms
53,852 KB
testcase_12 AC 41 ms
54,456 KB
testcase_13 AC 42 ms
55,224 KB
testcase_14 AC 41 ms
54,908 KB
testcase_15 AC 42 ms
55,400 KB
testcase_16 AC 42 ms
54,568 KB
testcase_17 AC 42 ms
53,744 KB
testcase_18 AC 42 ms
54,924 KB
testcase_19 AC 42 ms
53,932 KB
testcase_20 AC 41 ms
53,604 KB
testcase_21 AC 42 ms
54,792 KB
testcase_22 AC 42 ms
54,992 KB
testcase_23 AC 42 ms
54,592 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,A):
    Q=deque([V[0]])
    S={v:False for v in V}
    S[V[0]]=True
    T=[V[0]]

    while Q:
        v=Q.popleft()

        N=[]
        if v+1 in V and not S[v+1]:
            Q.append(v+1)
            T.append(v+1)
            S[v+1]=True
            
        if v-1 in V  and not S[v-1]:
            Q.append(v-1)
            T.append(v-1)
            S[v-1]=True
            
        if v+(W+2) in V  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 V  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),A))

print(k)
    
0