結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2020-02-12 01:07:43 |
言語 | Kotlin (2.1.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 991 bytes |
コンパイル時間 | 13,955 ms |
コンパイル使用メモリ | 439,760 KB |
実行使用メモリ | 56,696 KB |
最終ジャッジ日時 | 2024-10-01 14:22:11 |
合計ジャッジ時間 | 23,837 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 WA * 2 |
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'args' is never used fun main(args: Array<String>) { ^
ソースコード
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 move = BitSet.valueOf(longArrayOf(value.toLong())).cardinality() dp[value + move] = min(dp[value + move], dp[value] + 1) recUpdate(value + move) } 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] > dp[i] + 1 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) }