結果

問題 No.580 旅館の予約計画
ユーザー ThetaTheta
提出日時 2022-12-16 13:15:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 2,191 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-11-15 18:47:24
合計ジャッジ時間 2,956 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 29 ms
10,880 KB
testcase_03 AC 30 ms
11,008 KB
testcase_04 AC 30 ms
10,880 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 37 ms
11,008 KB
testcase_08 AC 31 ms
11,008 KB
testcase_09 AC 31 ms
11,008 KB
testcase_10 AC 33 ms
11,008 KB
testcase_11 AC 36 ms
11,008 KB
testcase_12 AC 38 ms
11,008 KB
testcase_13 AC 32 ms
11,008 KB
testcase_14 AC 38 ms
11,008 KB
testcase_15 AC 91 ms
11,264 KB
testcase_16 AC 64 ms
11,264 KB
testcase_17 AC 67 ms
11,136 KB
testcase_18 AC 68 ms
11,264 KB
testcase_19 AC 90 ms
11,264 KB
testcase_20 AC 57 ms
11,136 KB
testcase_21 AC 57 ms
11,136 KB
testcase_22 AC 40 ms
11,136 KB
testcase_23 AC 44 ms
11,136 KB
testcase_24 AC 50 ms
11,008 KB
testcase_25 AC 46 ms
11,136 KB
testcase_26 AC 31 ms
11,008 KB
testcase_27 AC 32 ms
11,008 KB
testcase_28 AC 29 ms
11,008 KB
testcase_29 AC 28 ms
10,752 KB
testcase_30 AC 46 ms
11,008 KB
testcase_31 AC 58 ms
11,008 KB
testcase_32 AC 45 ms
11,136 KB
testcase_33 AC 79 ms
11,264 KB
testcase_34 AC 44 ms
11,008 KB
testcase_35 AC 29 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import total_ordering


@total_ordering
class OrderTime:
    def __init__(self, day: int, hour: int, minute: int) -> None:
        self.hour = hour
        self.minute = minute
        self.day = day

    @property
    def time_tuple(self) -> tuple[int, int, int]:
        return self.day, self.hour, self.minute

    def __eq__(self, __o: object) -> bool:
        if not isinstance(__o, OrderTime):
            raise ValueError
        return self.time_tuple == __o.time_tuple

    def __lt__(self, __o: object) -> bool:
        if not isinstance(__o, OrderTime):
            raise ValueError
        return self.time_tuple < __o.time_tuple

    def __str__(self) -> str:
        return f"{self.day} {self.hour}:{self.minute}"


class Order:
    def __init__(self, enter_day, enter_hour, enter_minute, out_day, out_hour, out_minute) -> None:
        self.enter_time = OrderTime(enter_day, enter_hour, enter_minute)
        self.out_time = OrderTime(out_day, out_hour, out_minute)

    def can_stay(self, _o: object) -> bool:
        if not isinstance(_o, Order):
            raise ValueError
        return self.out_time < _o.enter_time


def main():
    n, m = map(int, input().split())
    orders: list[Order] = []
    for _ in range(m):
        enter_day, enter_time, out_day, out_time = input().split()
        enter_day = int(enter_day)
        out_day = int(out_day)
        enter_hour, enter_minute = map(int, enter_time.split(":"))
        out_hour, out_minute = map(int, out_time.split(":"))
        orders.append(Order(enter_day, enter_hour, enter_minute,
                            out_day, out_hour, out_minute))

    orders.sort(key=lambda order: order.out_time)

    ctr = 0
    rooms = [Order(1, 23, 50, 1, 23, 59) for _ in range(n)]

    for order in orders:
        next_order = [-1, (-1, -1, -1)]
        for room_idx, room in enumerate(rooms):
            if room.can_stay(order) and next_order[1] < room.out_time.time_tuple:
                next_order = [room_idx, room.out_time.time_tuple]
        if next_order[0] == -1:
            continue
        rooms[next_order[0]] = order
        ctr += 1

    print(ctr)


if __name__ == "__main__":
    main()
0