結果

問題 No.580 旅館の予約計画
ユーザー simansiman
提出日時 2022-03-14 02:33:01
言語 Ruby
(3.3.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 11,968 KB
実行使用メモリ 16,220 KB
最終ジャッジ日時 2023-10-19 15:10:00
合計ジャッジ時間 5,542 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
16,088 KB
testcase_01 AC 89 ms
16,088 KB
testcase_02 AC 93 ms
16,088 KB
testcase_03 AC 93 ms
16,088 KB
testcase_04 AC 97 ms
16,088 KB
testcase_05 AC 93 ms
16,088 KB
testcase_06 AC 93 ms
16,088 KB
testcase_07 AC 92 ms
16,088 KB
testcase_08 AC 92 ms
16,088 KB
testcase_09 AC 93 ms
16,088 KB
testcase_10 AC 94 ms
16,088 KB
testcase_11 AC 94 ms
16,088 KB
testcase_12 AC 95 ms
16,088 KB
testcase_13 AC 95 ms
16,088 KB
testcase_14 AC 97 ms
16,088 KB
testcase_15 AC 103 ms
16,220 KB
testcase_16 AC 100 ms
16,220 KB
testcase_17 AC 100 ms
16,220 KB
testcase_18 AC 101 ms
16,220 KB
testcase_19 AC 103 ms
16,220 KB
testcase_20 AC 97 ms
16,220 KB
testcase_21 AC 97 ms
16,220 KB
testcase_22 AC 95 ms
16,220 KB
testcase_23 AC 99 ms
16,220 KB
testcase_24 AC 97 ms
16,220 KB
testcase_25 AC 97 ms
16,220 KB
testcase_26 AC 92 ms
16,088 KB
testcase_27 AC 91 ms
16,088 KB
testcase_28 AC 96 ms
16,088 KB
testcase_29 AC 94 ms
16,088 KB
testcase_30 AC 104 ms
16,220 KB
testcase_31 AC 98 ms
16,220 KB
testcase_32 AC 106 ms
16,220 KB
testcase_33 AC 104 ms
16,220 KB
testcase_34 AC 100 ms
16,220 KB
testcase_35 AC 93 ms
16,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)

DAY = 24 * 60

def to_time(str)
  h, m = str.split(':').map(&:to_i)
  h * 60 + m
end

reserve_list = []

M.times do
  d, t1, o, t2 = gets.chomp.split
  from = d.to_i * DAY + to_time(t1)
  to = o.to_i * DAY + to_time(t2)

  reserve_list << [from, to]
end

reserve_list.sort_by! { |f, t| t }
rooms = Array.new(N, -1)
ans = 0

reserve_list.each do |from, to|
  best_id = -1
  max_time = -Float::INFINITY

  N.times do |i|
    if rooms[i] < from && max_time < rooms[i]
      best_id = i
      max_time = rooms[i]
    end
  end

  if best_id != -1
    rooms[best_id] = to
    ans += 1
  end
end

puts ans
0