結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-12 23:43:18 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 998 bytes |
| コンパイル時間 | 15,000 ms |
| コンパイル使用メモリ | 439,544 KB |
| 実行使用メモリ | 199,276 KB |
| 最終ジャッジ日時 | 2024-10-04 06:54:33 |
| 合計ジャッジ時間 | 19,358 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 1 TLE * 1 -- * 27 |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
^
Main.kt:8:52: warning: 'appendln(Any?): 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.
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 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 && distances[left] == -1) queue.add(left to distance + 1)
if (right in 1..n && distances[right] < distance + 1) queue.add(right to distance + 1)
}
val answer = distances[n]
println(answer)
}