結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-12 01:01:41 |
| 言語 | Kotlin (2.3.20) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,014 bytes |
| 記録 | |
| コンパイル時間 | 11,108 ms |
| コンパイル使用メモリ | 467,428 KB |
| 実行使用メモリ | 53,116 KB |
| 最終ジャッジ日時 | 2026-04-17 15:31:05 |
| 合計ジャッジ時間 | 18,848 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 15 |
ソースコード
import java.util.*
import kotlin.math.min
fun main(args: Array<String>) {
p11()
}
fun printString(builderAction: StringBuilder.() -> Unit) = print(buildString(builderAction))
fun p11() = printString {
val n = readLine()!!.toInt()
val inf = Int.MAX_VALUE / 100
val dp = IntArray(101010) { inf }
dp[1] = 1
fun recUpdate(value: Int) {
if (value !in 1..n) return
val move1 = BitSet.valueOf(longArrayOf(value.toLong())).cardinality()
dp[value + move1] = min(dp[value + move1], dp[value] + 1)
recUpdate(value + move1)
}
for (i in 1..n) {
val move = BitSet.valueOf(longArrayOf(i.toLong())).cardinality()
val left = i - move
val right = i + move
val needReCalc = dp[left] == inf
dp[right] = min(dp[right], dp[i] + 1)
dp[left] = min(dp[left], dp[i] + 1)
if (needReCalc) {
recUpdate(left)
}
}
val answer = dp[n].let { if (it == inf) -1 else it }
println(answer)
}