結果
問題 | No.697 池の数はいくつか |
ユーザー | Theta |
提出日時 | 2023-01-27 19:22:30 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,668 bytes |
コンパイル時間 | 75 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 163,712 KB |
最終ジャッジ日時 | 2024-06-28 04:45:05 |
合計ジャッジ時間 | 13,534 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
11,008 KB |
testcase_01 | AC | 29 ms
10,880 KB |
testcase_02 | AC | 29 ms
11,008 KB |
testcase_03 | AC | 28 ms
10,880 KB |
testcase_04 | AC | 30 ms
10,752 KB |
testcase_05 | AC | 29 ms
10,752 KB |
testcase_06 | AC | 29 ms
10,880 KB |
testcase_07 | AC | 29 ms
11,008 KB |
testcase_08 | AC | 29 ms
11,008 KB |
testcase_09 | AC | 29 ms
11,008 KB |
testcase_10 | AC | 29 ms
10,752 KB |
testcase_11 | AC | 30 ms
10,752 KB |
testcase_12 | AC | 27 ms
10,752 KB |
testcase_13 | AC | 30 ms
10,752 KB |
testcase_14 | AC | 30 ms
10,624 KB |
testcase_15 | AC | 28 ms
10,880 KB |
testcase_16 | AC | 28 ms
10,880 KB |
testcase_17 | AC | 30 ms
11,008 KB |
testcase_18 | AC | 29 ms
10,752 KB |
testcase_19 | AC | 29 ms
10,624 KB |
testcase_20 | AC | 29 ms
11,008 KB |
testcase_21 | AC | 29 ms
11,008 KB |
testcase_22 | AC | 29 ms
10,880 KB |
testcase_23 | AC | 29 ms
11,008 KB |
testcase_24 | AC | 733 ms
27,392 KB |
testcase_25 | AC | 736 ms
27,264 KB |
testcase_26 | AC | 729 ms
27,392 KB |
testcase_27 | AC | 713 ms
27,392 KB |
testcase_28 | AC | 739 ms
27,392 KB |
testcase_29 | TLE | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
ソースコード
from collections import deque from itertools import combinations, product def main(): H, W = map(int, input().split()) field_map = [list(map(int, input().split())) for _ in range(H)] searched = [[0]*W for _ in range(H)] pond_ctr = 0 for height_idx, width_idx in product(range(H), range(W)): if field_map[height_idx][width_idx] == 0: continue if searched[height_idx][width_idx] == 1: continue pond_ctr += 1 searching = deque(((height_idx, width_idx),)) searched[height_idx][width_idx] = 1 while searching: current_h_idx, current_w_idx = searching.popleft() if field_map[current_h_idx][current_w_idx] == 0: continue if current_h_idx < H-1 and searched[current_h_idx+1][current_w_idx] == 0: searching.append((current_h_idx+1, current_w_idx)) searched[current_h_idx+1][current_w_idx] = 1 if current_h_idx > 0 and searched[current_h_idx-1][current_w_idx] == 0: searching.append((current_h_idx-1, current_w_idx)) searched[current_h_idx-1][current_w_idx] = 1 if current_w_idx < W-1 and searched[current_h_idx][current_w_idx+1] == 0: searching.append((current_h_idx, current_w_idx+1)) searched[current_h_idx][current_w_idx+1] = 1 if current_w_idx > 0 and searched[current_h_idx][current_w_idx-1] == 0: searching.append((current_h_idx, current_w_idx-1)) searched[current_h_idx][current_w_idx-1] = 1 print(pond_ctr) if __name__ == "__main__": main()