結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2018-09-18 18:07:30 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,549 bytes | 
| コンパイル時間 | 188 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 98,304 KB | 
| 最終ジャッジ日時 | 2024-11-25 14:19:00 | 
| 合計ジャッジ時間 | 50,677 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 26 TLE * 6 | 
ソースコード
class No697:
    height, width = 0, 0
    cnt = 0
    def __init__(self):
        self.height, self.width = map(int, input().split(" "))
        # 高速化.1 内包表記
        self.water_map = [list(map(int, input().split(" "))) for _ in range(self.height)]
    def solve(self):
        for h in range(self.height):
            for w in range(self.width):
                if self.water_map[h][w] == 1:
                    search_queue = ((h, w),)
                    while len(search_queue) != 0:
                        copy_queue = search_queue
                        search_queue = tuple()
                        for py, px in copy_queue:
                            search_dic = [(0, 1, 0, -1), (1, 0, -1, 0)]
                            for i in range(4):
                                vx = px + search_dic[0][i]
                                vy = py + search_dic[1][i]
                                if 0 <= vx < self.width and 0 <= vy < self.height:
                                    if not self.water_map[vy][vx] == 0:
                                        comp = (py + search_dic[1][i], px + search_dic[0][i])
                                        if comp not in search_queue:
                                            search_queue += ((py + search_dic[1][i], px + search_dic[0][i]), )
                            self.water_map[py][px] = 0
                    self.cnt += 1
        return self.cnt
if __name__ == "__main__":
    que = No697()
    ans = que.solve()
    print(ans)