結果
問題 | No.1391 ±1 Abs Sum |
ユーザー | 👑 zeronosu77108 |
提出日時 | 2021-02-12 22:37:43 |
言語 | Kotlin (1.9.23) |
結果 |
WA
|
実行時間 | - |
コード長 | 652 bytes |
コンパイル時間 | 15,543 ms |
コンパイル使用メモリ | 422,796 KB |
実行使用メモリ | 99,344 KB |
最終ジャッジ日時 | 2023-09-27 05:25:28 |
合計ジャッジ時間 | 42,602 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 312 ms
57,416 KB |
testcase_01 | AC | 315 ms
57,228 KB |
testcase_02 | AC | 310 ms
57,076 KB |
testcase_03 | AC | 313 ms
57,144 KB |
testcase_04 | AC | 314 ms
57,184 KB |
testcase_05 | WA | - |
testcase_06 | AC | 316 ms
57,132 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 785 ms
70,528 KB |
testcase_15 | AC | 822 ms
70,496 KB |
testcase_16 | AC | 842 ms
78,692 KB |
testcase_17 | AC | 794 ms
76,912 KB |
testcase_18 | AC | 880 ms
79,900 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 975 ms
95,436 KB |
testcase_32 | AC | 736 ms
70,356 KB |
testcase_33 | AC | 751 ms
70,152 KB |
testcase_34 | AC | 938 ms
99,344 KB |
testcase_35 | AC | 298 ms
53,032 KB |
testcase_36 | AC | 907 ms
96,400 KB |
コンパイルメッセージ
Main.kt:9:23: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Long val amin = a.min()!! ^ Main.kt:10:23: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Long val amax = a.max()!! ^
ソースコード
import kotlin.collections.* import kotlin.math.* @kotlin.ExperimentalStdlibApi fun main() { val (n, k) = readLine()!!.split(" ").map { it.toInt() } val a = readLine()!!.split(" ").map { it.toLong() }.sorted() val amin = a.min()!! val amax = a.max()!! fun f(ai : Long) : Long { val l = a.map { abs(ai - it) }.toMutableList().sorted() return -l.sum() + l.take(k).sum() * 2 } var ans = minOf(f(amin), f(amax)) if (n%2 == 1) ans = minOf(ans, f(a[n/2])) else { ans = minOf(ans, f((a[n/2-1] + a[n/2]) / 2 ) ) ans = minOf(ans, f((a[n/2-1] + a[n/2]) / 2 +1) ) } println(ans) }