結果

問題 No.580 旅館の予約計画
ユーザー rutilicus
提出日時 2020-12-17 18:43:15
言語 Kotlin
(2.3.20)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,108 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,175 ms
コンパイル使用メモリ 436,372 KB
最終ジャッジ日時 2026-04-09 15:06:45
合計ジャッジ時間 8,993 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.kt:37:13: error: 'fun StringBuilder.appendln(value: Int): StringBuilder' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
    builder.appendln(ans)
            ^^^^^^^^

ソースコード

diff #
raw source code

fun main() {
    val builder = StringBuilder()

    // 区間スケジューリングの使い方分からない……
    val (n, m) = readInputLine().split(" ").map { it.toInt() }

    val timeList = mutableListOf<Pair<Int, Int>>()

    repeat(m) {
        val (d, hm, o, hmo) = readInputLine().split(" ")
        val (h, m) = hm.split(":")
        val (ho, mo) = hmo.split(":")
        timeList.add(Pair(d.toInt() * 24 * 60 + h.toInt() * 60 + m.toInt(),
                          o.toInt() * 24 * 60 + ho.toInt() * 60 + mo.toInt() + 1))
    }

    timeList.sortBy { it.first }
    timeList.sortBy { it.second }

    var ans = 0

    val room = IntArray(n) { -1 }

    for (t in timeList) {
        var maxIndex = -1
        for ((i, r) in room.withIndex()) {
            if (r <= t.first && (maxIndex == -1 || room[maxIndex] < r)) {
                maxIndex = i
            }
        }
        if (maxIndex != -1) {
            room[maxIndex] = t.second
            ans++
        }
    }

    builder.appendln(ans)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
0