結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,644 KB
testcase_01 AC 22 ms
8,648 KB
testcase_02 AC 21 ms
8,756 KB
testcase_03 AC 22 ms
8,700 KB
testcase_04 AC 21 ms
8,752 KB
testcase_05 AC 20 ms
8,752 KB
testcase_06 AC 20 ms
8,748 KB
testcase_07 AC 23 ms
8,696 KB
testcase_08 AC 23 ms
8,652 KB
testcase_09 AC 20 ms
8,700 KB
testcase_10 AC 20 ms
8,616 KB
testcase_11 AC 20 ms
8,612 KB
testcase_12 AC 20 ms
8,812 KB
testcase_13 AC 23 ms
8,612 KB
testcase_14 AC 22 ms
8,624 KB
testcase_15 AC 20 ms
8,748 KB
testcase_16 AC 20 ms
8,640 KB
testcase_17 AC 21 ms
8,804 KB
testcase_18 AC 23 ms
8,748 KB
testcase_19 AC 20 ms
8,752 KB
testcase_20 AC 21 ms
8,800 KB
testcase_21 AC 19 ms
8,812 KB
testcase_22 AC 22 ms
8,620 KB
testcase_23 AC 22 ms
8,700 KB
testcase_24 AC 591 ms
24,752 KB
testcase_25 AC 589 ms
24,764 KB
testcase_26 AC 580 ms
24,756 KB
testcase_27 AC 573 ms
24,700 KB
testcase_28 AC 574 ms
24,624 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