結果
問題 | No.1391 ±1 Abs Sum |
ユーザー | 👑 zeronosu77108 |
提出日時 | 2021-02-12 22:54:15 |
言語 | Kotlin (1.9.23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 735 bytes |
コンパイル時間 | 14,928 ms |
コンパイル使用メモリ | 425,332 KB |
実行使用メモリ | 92,368 KB |
最終ジャッジ日時 | 2023-09-27 05:55:07 |
合計ジャッジ時間 | 40,126 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 299 ms
60,680 KB |
testcase_01 | AC | 297 ms
90,520 KB |
testcase_02 | AC | 295 ms
61,404 KB |
testcase_03 | AC | 297 ms
57,128 KB |
testcase_04 | AC | 300 ms
57,284 KB |
testcase_05 | AC | 300 ms
57,004 KB |
testcase_06 | AC | 296 ms
57,440 KB |
testcase_07 | AC | 290 ms
57,004 KB |
testcase_08 | AC | 310 ms
57,072 KB |
testcase_09 | AC | 305 ms
57,256 KB |
testcase_10 | AC | 308 ms
57,532 KB |
testcase_11 | TLE | - |
testcase_12 | AC | 1,964 ms
84,536 KB |
testcase_13 | TLE | - |
testcase_14 | AC | 1,292 ms
81,608 KB |
testcase_15 | AC | 1,272 ms
81,796 KB |
testcase_16 | AC | 1,848 ms
83,492 KB |
testcase_17 | AC | 1,716 ms
82,344 KB |
testcase_18 | AC | 1,879 ms
86,248 KB |
testcase_19 | AC | 1,968 ms
82,732 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
コンパイルメッセージ
Main.kt:9:9: warning: variable 'amin' is never used val amin = a.min()!! ^ Main.kt:9:23: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Long val amin = a.min()!! ^ Main.kt:10:9: warning: variable 'amax' is never used val amax = a.max()!! ^ 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.take(k).sum() - l.takeLast(n-k).sum() } var l = 0; var r = n - 1 while(l + 10 < r) { val ll = (l+l+r) / 3 val rr = (l+r+r) / 3 if (f(a[ll]) < f(a[rr])) r = rr else l = ll } var ans = minOf(f(a.first()), f(a.last())) for (i in l .. r) { ans = minOf(ans, f(a[i])) } println(ans) }