結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
|
| 提出日時 | 2018-09-18 03:41:27 |
| 言語 | Python3 (3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 1,470 bytes |
| 記録 | |
| コンパイル時間 | 56 ms |
| コンパイル使用メモリ | 15,104 KB |
| 実行使用メモリ | 19,712 KB |
| 最終ジャッジ日時 | 2026-09-29 21:58:16 |
| 合計ジャッジ時間 | 11,533 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 TLE * 1 -- * 10 |
ソースコード
class No697:
height, width = 0, 0
cnt = 0
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):
pos_y, pos_x = self.search_water()
while not pos_y == -1 and not pos_x == -1:
search_queue = [(pos_x, pos_y)]
while len(search_queue) != 0:
px, py = search_queue.pop()
if self.water_map[py][px] == 1:
search_dic = [(0, 1, 0, -1), (1, 0, -1, 0)]
for i in range(4):
if 0 <= px + search_dic[0][i] < self.width and 0 <= py + search_dic[1][i] < self.height:
if self.water_map[py + search_dic[1][i]][px + search_dic[0][i]] == 1:
search_queue.append((px + search_dic[0][i], py + search_dic[1][i]))
self.water_map[py][px] = 0
self.cnt += 1
pos_y, pos_x = self.search_water()
return self.cnt
def search_water(self):
for i in range(self.height):
for j in range(self.width):
if self.water_map[i][j] == 1:
return i, j
return -1, -1
if __name__ == "__main__":
que = No697()
ans = que.solve()
print(ans)