結果
問題 | No.697 池の数はいくつか |
ユーザー |
|
提出日時 | 2023-01-27 19:15:18 |
言語 | Python3 (3.11.2 + numpy 1.24.2 + scipy 1.10.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,668 bytes |
コンパイル時間 | 98 ms |
コンパイル使用メモリ | 10,928 KB |
実行使用メモリ | 506,680 KB |
最終ジャッジ日時 | 2023-09-10 13:08:07 |
合計ジャッジ時間 | 18,952 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
13,000 KB |
testcase_01 | AC | 19 ms
8,560 KB |
testcase_02 | AC | 19 ms
8,632 KB |
testcase_03 | AC | 19 ms
8,608 KB |
testcase_04 | AC | 18 ms
8,596 KB |
testcase_05 | AC | 19 ms
8,588 KB |
testcase_06 | AC | 19 ms
8,604 KB |
testcase_07 | AC | 18 ms
8,548 KB |
testcase_08 | AC | 19 ms
8,636 KB |
testcase_09 | AC | 18 ms
8,624 KB |
testcase_10 | AC | 19 ms
8,660 KB |
testcase_11 | AC | 20 ms
8,748 KB |
testcase_12 | AC | 19 ms
8,588 KB |
testcase_13 | AC | 19 ms
8,656 KB |
testcase_14 | AC | 19 ms
8,624 KB |
testcase_15 | AC | 18 ms
8,628 KB |
testcase_16 | AC | 18 ms
8,560 KB |
testcase_17 | AC | 19 ms
8,660 KB |
testcase_18 | AC | 20 ms
8,600 KB |
testcase_19 | AC | 18 ms
8,556 KB |
testcase_20 | AC | 19 ms
8,560 KB |
testcase_21 | AC | 19 ms
8,684 KB |
testcase_22 | AC | 19 ms
8,556 KB |
testcase_23 | AC | 19 ms
8,752 KB |
testcase_24 | AC | 1,431 ms
139,624 KB |
testcase_25 | AC | 1,443 ms
139,456 KB |
testcase_26 | AC | 1,440 ms
139,616 KB |
testcase_27 | AC | 1,447 ms
139,472 KB |
testcase_28 | AC | 1,446 ms
139,656 KB |
testcase_29 | MLE | - |
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)] pond_ctr = 0 searched = set() for height_idx, width_idx in product(range(H), range(W)): if field_map[height_idx][width_idx] == 0: continue if (height_idx, width_idx) in searched: continue pond_ctr += 1 searching = deque(((height_idx, width_idx),)) searched.add((height_idx, width_idx)) 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 (current_h_idx+1, current_w_idx) not in searched: searching.append((current_h_idx+1, current_w_idx)) searched.add((current_h_idx+1, current_w_idx)) if current_h_idx > 0 and (current_h_idx-1, current_w_idx) not in searched: searching.append((current_h_idx-1, current_w_idx)) searched.add((current_h_idx-1, current_w_idx)) if current_w_idx < W-1 and (current_h_idx, current_w_idx+1) not in searched: searching.append((current_h_idx, current_w_idx+1)) searched.add((current_h_idx, current_w_idx+1)) if current_w_idx > 0 and (current_h_idx, current_w_idx-1) not in searched: searching.append((current_h_idx, current_w_idx-1)) searched.add((current_h_idx, current_w_idx-1)) print(pond_ctr) if __name__ == "__main__": main()