結果

問題 No.697 池の数はいくつか
ユーザー syunsuke
提出日時 2018-06-22 00:07:32
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,923 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 98,432 KB
最終ジャッジ日時 2024-11-25 13:43:01
合計ジャッジ時間 51,872 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

HW=input()
HW=HW.rstrip().split(" ")
H=int(HW[0])
W=int(HW[1])

list1=[]
list1.append([2]*(W+2))

for i in range(H):
    list2=[2]
    line=input()
    line=line.rstrip().split(" ")
    for j in range(W):
        list2.append(int(line[j]))
    list2.append(2)
    list1.append(list2)
list1.append([2]*(W+2))
    
#print(list1)

count=0
box=[]
for k in range(1,H+1):
    
    for l in range(1,W+1):
        
        if list1[k][l]==1:
            #print(list1)
            count=count+1
            list1[k][l]=3
            if list1[k][l+1]==1:
                box.append([k,l+1])
            if list1[k][l-1]==1:
                box.append([k,l-1])
            if list1[k+1][l]==1:
                box.append([k+1,l])
            if list1[k-1][l]==1:
                box.append([k-1,l])
            if len(box)==0:
                pass
            else:
                for n in range(H*W):
                    list1[box[0][0]][box[0][1]]=3
                    if list1[box[0][0]][box[0][1]+1]==1:
                        if [box[0][0],box[0][1]+1] not in box:
                            box.append([box[0][0],box[0][1]+1])
                    if list1[box[0][0]][box[0][1]-1]==1:
                        if [box[0][0],box[0][1]-1] not in box:
                            box.append([box[0][0],box[0][1]-1])
                    if list1[box[0][0]+1][box[0][1]]==1:
                        if [box[0][0]+1,box[0][1]] not in box:
                            box.append([box[0][0]+1,box[0][1]])
                    if list1[box[0][0]-1][box[0][1]]==1:
                        if [box[0][0]-1,box[0][1]] not in box:
                            box.append([box[0][0]-1,box[0][1]])
                    box.pop(0)
                    if len(box)==0:
                        break
                    else:
                        #print(box)
                        n+=1
        else:
            l+=1
#print(list1)
print(count)
0