結果
問題 | No.697 池の数はいくつか |
ユーザー | Pump0129 |
提出日時 | 2018-09-18 04:18:59 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,995 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 94,368 KB |
最終ジャッジ日時 | 2024-05-04 06:12:01 |
合計ジャッジ時間 | 22,247 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
10,880 KB |
testcase_01 | AC | 28 ms
10,752 KB |
testcase_02 | AC | 27 ms
10,752 KB |
testcase_03 | AC | 28 ms
10,752 KB |
testcase_04 | AC | 27 ms
10,880 KB |
testcase_05 | AC | 27 ms
10,880 KB |
testcase_06 | AC | 27 ms
10,880 KB |
testcase_07 | AC | 27 ms
10,880 KB |
testcase_08 | AC | 27 ms
10,880 KB |
testcase_09 | AC | 27 ms
10,752 KB |
testcase_10 | WA | - |
testcase_11 | AC | 27 ms
10,880 KB |
testcase_12 | AC | 26 ms
10,752 KB |
testcase_13 | WA | - |
testcase_14 | AC | 27 ms
11,008 KB |
testcase_15 | AC | 26 ms
10,880 KB |
testcase_16 | AC | 26 ms
10,752 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 28 ms
10,752 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 27 ms
10,752 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | TLE | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
ソースコード
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)] for i in range(self.height): for j in range(self.width): if self.water_map[i][j] == 1: pos_id = self.id for k in range(4): vx = j + search_dic[0][k] vy = i + search_dic[1][k] if 0 <= vx < self.width and 0 <= vy < self.height: if not self.water_map[vy][vx] == 0 and not self.water_map[vy][vx] == 1: pos_id = self.water_map[vy][vx] self.water_map[i][j] = pos_id if pos_id == self.id: self.id += 1 for i in range(self.height): for j in range(self.width): my_id = self.water_map[i][j] c_id = my_id if not my_id == 0: for k in range(4): vx = j + search_dic[0][k] vy = i + search_dic[1][k] if 0 <= vx < self.width and 0 <= vy < self.height: if not self.water_map[vy][vx] == 0 and not self.water_map[vy][vx] == my_id: c_id = self.water_map[vy][vx] self.water_map[i][j] = c_id num_set = set() for num_list in self.water_map: num_set = num_set | set(num_list) if num_set.isdisjoint({0}): return len(num_set) else: return len(num_set) - 1 if __name__ == "__main__": que = No697() ans = que.solve() print(ans)