結果

問題 No.697 池の数はいくつか
ユーザー 👑 KazunKazun
提出日時 2020-06-03 00:05:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,059 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 133,816 KB
最終ジャッジ日時 2024-05-04 07:00:35
合計ジャッジ時間 9,750 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
11,008 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 30 ms
11,008 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 30 ms
10,880 KB
testcase_07 AC 31 ms
10,752 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 31 ms
10,880 KB
testcase_10 AC 32 ms
11,008 KB
testcase_11 AC 30 ms
10,880 KB
testcase_12 AC 30 ms
10,880 KB
testcase_13 AC 30 ms
10,752 KB
testcase_14 AC 31 ms
10,880 KB
testcase_15 AC 32 ms
11,136 KB
testcase_16 AC 31 ms
10,880 KB
testcase_17 AC 32 ms
10,880 KB
testcase_18 AC 31 ms
10,880 KB
testcase_19 AC 30 ms
10,752 KB
testcase_20 AC 31 ms
11,136 KB
testcase_21 AC 31 ms
10,880 KB
testcase_22 AC 31 ms
10,880 KB
testcase_23 AC 31 ms
10,880 KB
testcase_24 TLE -
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