結果
問題 | No.697 池の数はいくつか |
ユーザー |
|
提出日時 | 2023-01-27 19:25:32 |
言語 | PyPy3 (7.3.11) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,674 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 86,936 KB |
実行使用メモリ | 437,644 KB |
最終ジャッジ日時 | 2023-09-10 13:18:14 |
合計ジャッジ時間 | 24,862 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
71,508 KB |
testcase_01 | AC | 91 ms
71,276 KB |
testcase_02 | AC | 93 ms
71,584 KB |
testcase_03 | AC | 94 ms
71,536 KB |
testcase_04 | AC | 91 ms
71,508 KB |
testcase_05 | AC | 92 ms
71,640 KB |
testcase_06 | AC | 92 ms
71,136 KB |
testcase_07 | AC | 89 ms
71,544 KB |
testcase_08 | AC | 92 ms
71,168 KB |
testcase_09 | AC | 91 ms
71,336 KB |
testcase_10 | AC | 94 ms
71,128 KB |
testcase_11 | AC | 93 ms
71,588 KB |
testcase_12 | AC | 92 ms
71,168 KB |
testcase_13 | AC | 91 ms
71,680 KB |
testcase_14 | AC | 92 ms
71,712 KB |
testcase_15 | AC | 93 ms
71,664 KB |
testcase_16 | AC | 92 ms
71,336 KB |
testcase_17 | AC | 96 ms
71,404 KB |
testcase_18 | AC | 93 ms
71,136 KB |
testcase_19 | AC | 94 ms
71,600 KB |
testcase_20 | AC | 93 ms
71,460 KB |
testcase_21 | AC | 93 ms
71,268 KB |
testcase_22 | AC | 89 ms
71,768 KB |
testcase_23 | AC | 93 ms
71,640 KB |
testcase_24 | AC | 484 ms
111,508 KB |
testcase_25 | AC | 478 ms
112,008 KB |
testcase_26 | AC | 489 ms
111,712 KB |
testcase_27 | AC | 463 ms
111,760 KB |
testcase_28 | AC | 466 ms
111,624 KB |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | MLE | - |
testcase_32 | MLE | - |
testcase_33 | MLE | - |
testcase_34 | MLE | - |
ソースコード
from collections import deque from itertools import combinations, product def main(): H, W = map(int, input().split()) field_map = tuple(tuple(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()