結果
| 問題 | No.580 旅館の予約計画 |
| ユーザー |
rutilicus
|
| 提出日時 | 2020-12-17 18:43:15 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 424 ms / 2,000 ms |
| コード長 | 1,108 bytes |
| コンパイル時間 | 15,451 ms |
| コンパイル使用メモリ | 439,936 KB |
| 実行使用メモリ | 53,440 KB |
| 最終ジャッジ日時 | 2024-09-21 08:11:44 |
| 合計ジャッジ時間 | 27,459 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
コンパイルメッセージ
Main.kt:11:17: warning: name shadowed: m
val (h, m) = hm.split(":")
^
Main.kt:37:13: warning: 'appendln(Int): kotlin.text.StringBuilder /* = java.lang.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)
^
ソースコード
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()!!
}
rutilicus