結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2018-09-18 17:02:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,702 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 100,208 KB |
最終ジャッジ日時 | 2024-11-25 14:13:04 |
合計ジャッジ時間 | 80,156 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 TLE * 11 |
ソースコード
class No697: height, width = 0, 0 id = 2 def __init__(self): self.height, self.width = map(int, input().split(" ")) self.water_map = [[0 for i in range(self.width)] for j in range(self.height)] for i in range(self.height): self.water_map[i] = list(map(int, input().split(" "))) def solve(self): search_dic = [(0, 1, 0, -1), (1, 0, -1, 0)] remove_id_list = set() for h in range(self.height): for w in range(self.width): if self.water_map[h][w] == 1: pos_id = self.id id_list = set() for k in range(4): vx = w + search_dic[0][k] vy = h + search_dic[1][k] if 0 <= vx < self.width and 0 <= vy < self.height: if 2 <= self.water_map[vy][vx]: id_list.add(self.water_map[vy][vx]) if 2 <= len(id_list): pos_id = min(id_list) id_list.remove(min(id_list)) remove_id_list = id_list | remove_id_list elif 1 == len(id_list): pos_id = id_list.pop() self.water_map[h][w] = pos_id if self.id == pos_id: self.id += 1 num_set = set() for num_list in self.water_map: num_set = num_set | set(num_list) return len(num_set) - len(num_set & (remove_id_list | {0})) if __name__ == "__main__": que = No697() ans = que.solve() print(ans)