結果

問題 No.580 旅館の予約計画
ユーザー mkawa2mkawa2
提出日時 2020-01-05 16:19:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,391 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 8,436 KB
最終ジャッジ日時 2023-08-14 22:03:32
合計ジャッジ時間 2,224 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,128 KB
testcase_01 AC 15 ms
8,112 KB
testcase_02 AC 15 ms
8,084 KB
testcase_03 AC 17 ms
8,120 KB
testcase_04 AC 17 ms
8,040 KB
testcase_05 AC 17 ms
8,160 KB
testcase_06 AC 17 ms
8,248 KB
testcase_07 AC 16 ms
8,252 KB
testcase_08 AC 17 ms
8,356 KB
testcase_09 AC 17 ms
8,212 KB
testcase_10 AC 17 ms
8,340 KB
testcase_11 AC 17 ms
8,108 KB
testcase_12 AC 18 ms
8,320 KB
testcase_13 AC 17 ms
8,380 KB
testcase_14 AC 20 ms
8,436 KB
testcase_15 AC 22 ms
8,116 KB
testcase_16 AC 22 ms
8,096 KB
testcase_17 AC 23 ms
8,160 KB
testcase_18 AC 23 ms
8,084 KB
testcase_19 AC 22 ms
8,124 KB
testcase_20 AC 22 ms
8,096 KB
testcase_21 AC 22 ms
8,028 KB
testcase_22 AC 22 ms
8,108 KB
testcase_23 AC 22 ms
8,184 KB
testcase_24 AC 23 ms
8,196 KB
testcase_25 AC 22 ms
8,160 KB
testcase_26 AC 16 ms
8,352 KB
testcase_27 AC 16 ms
8,216 KB
testcase_28 AC 16 ms
8,072 KB
testcase_29 AC 16 ms
8,128 KB
testcase_30 AC 22 ms
8,164 KB
testcase_31 AC 22 ms
8,048 KB
testcase_32 AC 22 ms
8,072 KB
testcase_33 AC 23 ms
8,040 KB
testcase_34 AC 22 ms
8,040 KB
testcase_35 AC 17 ms
8,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
def MI(): return map(int, sys.stdin.readline().split())

def main():
    def stod(s):
        res = int(s[0]) * 10000 + int(s[2:4]) * 100 + int(s[5:7])
        return res

    n, m = MI()
    if n > m:
        print(m)
        exit()
    timeline = []
    for i in range(m):
        s = input()
        date0 = stod(s[:7])
        date1 = stod(s[8:])
        # [時間,0到着,退出時間,客番号]
        heappush(timeline, [date0, 0, date1, i])
    ans = 0
    stay = 0
    arrived = []
    leaved = [False] * m
    while timeline:
        date0, event, date1, i = heappop(timeline)
        # チェックアウト
        if event:
            if leaved[i]: continue
            # 追い出されずにチェックアウトできた人数が答え
            ans += 1
            stay -= 1
            leaved[i] = True
        # チェックイン
        else:
            heappush(arrived, [-date1, i])
            # [時間,1退出,なし,客番号]
            heappush(timeline, [date1, 1, -1, i])
            stay += 1
        # 収容人数を越えたら、チェックアウトが一番遅い客を追い出す
        if stay > n:
            while 1:
                date1, i = heappop(arrived)
                if not leaved[i]: break
            stay -= 1
            leaved[i] = True

    print(ans)

main()
0