結果
問題 | No.838 Noelちゃんと星々3 |
ユーザー | rutilicus |
提出日時 | 2020-11-03 10:07:45 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 698 ms / 2,000 ms |
コード長 | 769 bytes |
コンパイル時間 | 14,705 ms |
コンパイル使用メモリ | 413,248 KB |
実行使用メモリ | 66,452 KB |
最終ジャッジ日時 | 2023-09-29 14:31:10 |
合計ジャッジ時間 | 28,175 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 676 ms
65,584 KB |
testcase_01 | AC | 674 ms
65,516 KB |
testcase_02 | AC | 698 ms
65,484 KB |
testcase_03 | AC | 667 ms
66,452 KB |
testcase_04 | AC | 672 ms
65,528 KB |
testcase_05 | AC | 305 ms
56,996 KB |
testcase_06 | AC | 301 ms
57,308 KB |
testcase_07 | AC | 308 ms
56,924 KB |
testcase_08 | AC | 305 ms
56,940 KB |
testcase_09 | AC | 306 ms
57,040 KB |
testcase_10 | AC | 304 ms
57,052 KB |
testcase_11 | AC | 305 ms
56,992 KB |
testcase_12 | AC | 306 ms
56,980 KB |
testcase_13 | AC | 305 ms
56,884 KB |
testcase_14 | AC | 298 ms
57,168 KB |
testcase_15 | AC | 304 ms
57,356 KB |
testcase_16 | AC | 297 ms
56,804 KB |
testcase_17 | AC | 296 ms
56,948 KB |
testcase_18 | AC | 307 ms
57,192 KB |
testcase_19 | AC | 306 ms
56,924 KB |
testcase_20 | AC | 297 ms
57,072 KB |
testcase_21 | AC | 297 ms
56,992 KB |
testcase_22 | AC | 295 ms
56,992 KB |
testcase_23 | AC | 294 ms
57,116 KB |
testcase_24 | AC | 298 ms
56,820 KB |
testcase_25 | AC | 295 ms
57,116 KB |
testcase_26 | AC | 292 ms
56,812 KB |
testcase_27 | AC | 296 ms
57,152 KB |
testcase_28 | AC | 301 ms
56,940 KB |
コンパイルメッセージ
Main.kt:13:22: warning: 'appendln(Long): 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. 2 -> builder.appendln(ys[1] - ys[0]) ^ Main.kt:14:22: warning: 'appendln(Long): 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. 3 -> builder.appendln(ys[2] - ys[0]) ^ Main.kt:23:21: warning: 'appendln(Long): 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(dp[n - 1]) ^
ソースコード
import kotlin.math.min fun main() { val builder = StringBuilder() // 解説読んだ val n = readInputLine().toInt() val ys = readInputLine().split(" ").map { it.toLong() }.toLongArray() ys.sort() when(n) { 2 -> builder.appendln(ys[1] - ys[0]) 3 -> builder.appendln(ys[2] - ys[0]) else -> { val dp = LongArray(n) dp[0] = 1_000_000_000_000L dp[1] = ys[1] - ys[0] dp[2] = ys[2] - ys[0] for (i in 3 until n) { dp[i] = min(dp[i - 2] + ys[i] - ys[i - 1], dp[i - 3] + ys[i] - ys[i - 2]) } builder.appendln(dp[n - 1]) } } print(builder.toString()) } fun readInputLine(): String { return readLine()!! }