結果

問題 No.697 池の数はいくつか
ユーザー 双六双六
提出日時 2020-08-26 15:19:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,125 ms / 6,000 ms
コード長 913 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 254,864 KB
最終ジャッジ日時 2024-04-25 20:50:37
合計ジャッジ時間 10,851 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,032 KB
testcase_01 AC 37 ms
54,608 KB
testcase_02 AC 37 ms
54,720 KB
testcase_03 AC 37 ms
55,424 KB
testcase_04 AC 37 ms
55,396 KB
testcase_05 AC 37 ms
54,432 KB
testcase_06 AC 37 ms
54,588 KB
testcase_07 AC 35 ms
54,796 KB
testcase_08 AC 36 ms
55,036 KB
testcase_09 AC 37 ms
55,068 KB
testcase_10 AC 37 ms
54,184 KB
testcase_11 AC 37 ms
54,488 KB
testcase_12 AC 38 ms
54,064 KB
testcase_13 AC 38 ms
54,260 KB
testcase_14 AC 38 ms
54,556 KB
testcase_15 AC 38 ms
54,560 KB
testcase_16 AC 39 ms
54,684 KB
testcase_17 AC 40 ms
54,320 KB
testcase_18 AC 40 ms
54,312 KB
testcase_19 AC 41 ms
54,616 KB
testcase_20 AC 40 ms
54,116 KB
testcase_21 AC 38 ms
55,244 KB
testcase_22 AC 40 ms
54,112 KB
testcase_23 AC 40 ms
54,184 KB
testcase_24 AC 241 ms
87,344 KB
testcase_25 AC 236 ms
87,424 KB
testcase_26 AC 238 ms
87,364 KB
testcase_27 AC 229 ms
87,644 KB
testcase_28 AC 258 ms
87,984 KB
testcase_29 AC 1,062 ms
254,540 KB
testcase_30 AC 1,084 ms
172,492 KB
testcase_31 AC 1,125 ms
254,864 KB
testcase_32 AC 1,080 ms
172,772 KB
testcase_33 AC 1,078 ms
173,256 KB
testcase_34 AC 1,076 ms
172,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
# from collections import defaultdict
from collections import deque

def getlist():
	return list(map(int, input().split()))

def BFS(H, W, L, start):
	h, w = start
	Q = deque(); Q.append([h, w])
	while Q:
		y, x = Q.popleft()
		if L[y - 1][x] == 1:
			L[y - 1][x] = 2
			Q.append([y - 1, x])
		if L[y + 1][x] == 1:
			L[y + 1][x] = 2
			Q.append([y + 1, x])
		if L[y][x - 1] == 1:
			L[y][x - 1] = 2
			Q.append([y, x - 1])
		if L[y][x + 1] == 1:
			L[y][x + 1] = 2
			Q.append([y, x + 1])

#処理内容
def main():
	H, W = getlist()
	L = []
	L.append([0] * (W + 2))
	for i in range(H):
		l = getlist()
		L.append([0] + l + [0])
	L.append([0] * (W + 2))

	cnt = 0
	for i in range(1, H + 1):
		for j in range(1, W + 1):
			if L[i][j] == 1:
				cnt += 1
				BFS(H + 2, W + 2, L, [i, j])

	print(cnt)

if __name__ == '__main__':
	main()
0