結果

問題 No.697 池の数はいくつか
ユーザー syunsukesyunsuke
提出日時 2018-06-22 00:07:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,923 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 94,624 KB
最終ジャッジ日時 2024-05-04 05:57:24
合計ジャッジ時間 16,095 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
11,136 KB
testcase_01 AC 26 ms
11,008 KB
testcase_02 AC 26 ms
11,008 KB
testcase_03 AC 27 ms
11,008 KB
testcase_04 AC 26 ms
11,008 KB
testcase_05 AC 26 ms
11,008 KB
testcase_06 AC 27 ms
11,008 KB
testcase_07 AC 26 ms
11,136 KB
testcase_08 AC 26 ms
11,008 KB
testcase_09 AC 27 ms
11,136 KB
testcase_10 AC 28 ms
11,008 KB
testcase_11 AC 28 ms
11,008 KB
testcase_12 AC 27 ms
11,008 KB
testcase_13 AC 27 ms
11,008 KB
testcase_14 AC 28 ms
11,136 KB
testcase_15 AC 27 ms
11,008 KB
testcase_16 AC 26 ms
11,008 KB
testcase_17 AC 26 ms
11,136 KB
testcase_18 AC 28 ms
11,008 KB
testcase_19 AC 27 ms
11,008 KB
testcase_20 AC 26 ms
11,008 KB
testcase_21 AC 25 ms
11,008 KB
testcase_22 AC 26 ms
11,008 KB
testcase_23 AC 26 ms
11,008 KB
testcase_24 AC 1,260 ms
19,712 KB
testcase_25 AC 1,279 ms
19,840 KB
testcase_26 AC 1,266 ms
19,584 KB
testcase_27 AC 1,239 ms
19,584 KB
testcase_28 AC 1,284 ms
19,712 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

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