結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-12 23:49:00 |
| 言語 | Kotlin (2.3.10) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,019 bytes |
| 記録 | |
| コンパイル時間 | 7,638 ms |
| コンパイル使用メモリ | 405,796 KB |
| 最終ジャッジ日時 | 2026-03-22 07:15:26 |
| 合計ジャッジ時間 | 8,049 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Main.kt:8:52: error: 'fun StringBuilder.appendln(value: Any?): StringBuilder' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
private fun StringBuilder.println(message: Any?) = appendln(message)
^^^^^^^^
ソースコード
import java.util.*
fun main(args: Array<String>) {
p11()
}
private inline fun printString(builderAction: StringBuilder.() -> Unit) = print(buildString(builderAction))
private fun StringBuilder.println(message: Any?) = appendln(message)
private fun StringBuilder.print(message: Any?) = append(message)
fun p11() = printString {
val n = readLine()!!.toInt()
val distances = IntArray(101010) { -1 }
val visited = mutableSetOf<Int>()
val queue = ArrayDeque(listOf(1 to 1))
fun getMoveDistance(value: Int): Int = Integer.bitCount(value)
while (queue.isNotEmpty()) {
val (position, distance) = queue.poll()
distances[position] = distance
val move = getMoveDistance(position)
val left = position - move
val right = position + move
if (left in 1..n && visited.add(left)) queue.add(left to distance + 1)
if (right in 1..n && visited.add(right)) queue.add(right to distance + 1)
}
val answer = distances[n]
println(answer)
}