結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,644 KB
testcase_01 AC 19 ms
8,788 KB
testcase_02 AC 19 ms
8,652 KB
testcase_03 AC 19 ms
8,636 KB
testcase_04 AC 19 ms
8,820 KB
testcase_05 AC 19 ms
8,616 KB
testcase_06 AC 19 ms
8,688 KB
testcase_07 AC 19 ms
8,640 KB
testcase_08 AC 19 ms
8,700 KB
testcase_09 AC 19 ms
8,796 KB
testcase_10 AC 19 ms
8,648 KB
testcase_11 AC 19 ms
8,788 KB
testcase_12 AC 19 ms
8,784 KB
testcase_13 AC 19 ms
8,828 KB
testcase_14 AC 19 ms
8,800 KB
testcase_15 AC 19 ms
8,752 KB
testcase_16 AC 19 ms
8,652 KB
testcase_17 AC 19 ms
8,612 KB
testcase_18 AC 18 ms
8,824 KB
testcase_19 AC 19 ms
8,740 KB
testcase_20 AC 18 ms
8,688 KB
testcase_21 AC 19 ms
8,696 KB
testcase_22 AC 18 ms
8,788 KB
testcase_23 AC 20 ms
8,636 KB
testcase_24 AC 563 ms
24,640 KB
testcase_25 AC 562 ms
24,716 KB
testcase_26 AC 561 ms
24,796 KB
testcase_27 AC 559 ms
24,668 KB
testcase_28 AC 565 ms
24,812 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
con = 10 ** 9 + 7; INF = float("inf")

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

def BFS(H, W, L, visit, start):
	h, w = start
	Q = deque(); Q.append([h, w])
	while Q:
		y, x = Q.popleft()
		if L[y - 1][x] == 1 and visit[y - 1][x] == 0:
			visit[y - 1][x] = 1
			Q.append([y - 1, x])
		if L[y + 1][x] == 1 and visit[y + 1][x] == 0:
			visit[y + 1][x] = 1
			Q.append([y + 1, x])
		if L[y][x - 1] == 1 and visit[y][x - 1] == 0:
			visit[y][x - 1] = 1
			Q.append([y, x - 1])
		if L[y][x + 1] == 1 and visit[y][x + 1] == 0:
			visit[y][x + 1] = 1
			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))

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

	print(cnt)

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