結果

問題 No.697 池の数はいくつか
ユーザー 双六双六
提出日時 2020-08-26 15:19:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 913 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 11,020 KB
実行使用メモリ 16,768 KB
最終ジャッジ日時 2023-08-16 23:41:49
合計ジャッジ時間 12,012 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,784 KB
testcase_01 AC 18 ms
8,636 KB
testcase_02 AC 18 ms
8,628 KB
testcase_03 AC 19 ms
8,692 KB
testcase_04 AC 19 ms
8,552 KB
testcase_05 AC 19 ms
8,580 KB
testcase_06 AC 18 ms
8,716 KB
testcase_07 AC 19 ms
8,676 KB
testcase_08 AC 19 ms
8,584 KB
testcase_09 AC 18 ms
8,700 KB
testcase_10 AC 19 ms
8,704 KB
testcase_11 AC 18 ms
8,688 KB
testcase_12 AC 18 ms
8,628 KB
testcase_13 AC 18 ms
8,564 KB
testcase_14 AC 18 ms
8,696 KB
testcase_15 AC 19 ms
8,568 KB
testcase_16 AC 18 ms
8,680 KB
testcase_17 AC 18 ms
8,624 KB
testcase_18 AC 19 ms
8,632 KB
testcase_19 AC 19 ms
8,628 KB
testcase_20 AC 19 ms
8,704 KB
testcase_21 AC 18 ms
8,624 KB
testcase_22 AC 19 ms
8,552 KB
testcase_23 AC 18 ms
8,700 KB
testcase_24 AC 456 ms
16,636 KB
testcase_25 AC 456 ms
16,768 KB
testcase_26 AC 459 ms
16,760 KB
testcase_27 AC 457 ms
16,764 KB
testcase_28 AC 456 ms
16,700 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

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