結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,368 KB
testcase_01 AC 42 ms
55,512 KB
testcase_02 AC 40 ms
54,068 KB
testcase_03 AC 38 ms
54,428 KB
testcase_04 AC 38 ms
55,308 KB
testcase_05 AC 39 ms
54,936 KB
testcase_06 AC 39 ms
54,572 KB
testcase_07 AC 38 ms
55,644 KB
testcase_08 AC 38 ms
54,128 KB
testcase_09 AC 39 ms
53,748 KB
testcase_10 AC 41 ms
54,912 KB
testcase_11 AC 40 ms
55,072 KB
testcase_12 AC 41 ms
54,672 KB
testcase_13 AC 44 ms
54,880 KB
testcase_14 AC 43 ms
54,456 KB
testcase_15 AC 43 ms
54,720 KB
testcase_16 AC 44 ms
55,372 KB
testcase_17 AC 44 ms
54,192 KB
testcase_18 AC 42 ms
55,352 KB
testcase_19 AC 40 ms
55,384 KB
testcase_20 AC 40 ms
54,328 KB
testcase_21 AC 38 ms
54,664 KB
testcase_22 AC 38 ms
54,252 KB
testcase_23 AC 41 ms
55,328 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
def BFS(V,E):    
    Q=deque([V[0]])
    S={v:False for v in V}
    S[V[0]]=True
    T=[V[0]]

    while Q:
        v=Q.popleft()
        N=[w for w in V if ((v,w) in E) and (not S[w])]

        for w in N:
            Q.append(w)
            T.append(w)
            S[w]=True

    return T

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))

A=[[0]*(W+2)]
for i in range(H):
    A.append([0]+list(map(int,input().split()))+[0])
A+=[[0]*(W+2)]

V=[]
for y in range(H+2):
    for x in range(W+2):
        if A[y][x]==1:
            V.append(f(x,y))

E=set()
for n in V:
    (x,y)=g(n)
    if A[y][x]==1:
        if A[y][x+1]==1:
            E|={(f(x,y),f(x+1,y)),(f(x+1,y),f(x,y))}
        if A[y+1][x]==1:
            E|={(f(x,y),f(x,y+1)),(f(x,y+1),f(x,y))}

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

print(k)
    
0