結果

問題 No.697 池の数はいくつか
ユーザー Pump0129Pump0129
提出日時 2018-09-18 04:18:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,995 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 89,448 KB
最終ジャッジ日時 2023-08-16 22:49:31
合計ジャッジ時間 20,903 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,168 KB
testcase_01 AC 17 ms
8,072 KB
testcase_02 AC 17 ms
8,004 KB
testcase_03 AC 16 ms
8,088 KB
testcase_04 AC 16 ms
8,028 KB
testcase_05 AC 16 ms
8,136 KB
testcase_06 AC 17 ms
8,052 KB
testcase_07 AC 16 ms
8,012 KB
testcase_08 AC 16 ms
8,168 KB
testcase_09 AC 16 ms
8,084 KB
testcase_10 WA -
testcase_11 AC 16 ms
8,088 KB
testcase_12 AC 16 ms
8,164 KB
testcase_13 WA -
testcase_14 AC 17 ms
8,024 KB
testcase_15 AC 16 ms
8,024 KB
testcase_16 AC 17 ms
8,144 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 17 ms
8,076 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 16 ms
8,024 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0