結果

問題 No.697 池の数はいくつか
ユーザー Mr.Fuku
提出日時 2018-06-23 21:29:19
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 578 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 87,552 KB
最終ジャッジ日時 2024-11-25 13:52:31
合計ジャッジ時間 34,166 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = input().split()
h,w = int(h),int(w)

lst = []
cnt = 0

def tansaku(x,y):
    lst[x][y]=0
    if lst[x+1][y]==1:
        tansaku(x+1,y)
    if lst[x-1][y]==1:
        tansaku(x-1,y)
    if lst[x][y+1]==1:
        tansaku(x,y+1)
    if lst[x][y-1]==1:
        tansaku(x,y-1)

for a in range(h):
    l = [0]
    for b in input().split():
        l.append(int(b))
    l.append(0)
    lst.append(l)
lst.insert(0,[0]*(w+2))
lst.append([0]*(w+2))

for a in range(1,h+1):
    for b in range(1,w+1):
        if lst[a][b]==1:
            cnt+=1
            tansaku(a,b)

print(cnt)
0