結果

問題 No.1282 Display Elements
ユーザー rutilicusrutilicus
提出日時 2020-11-07 22:14:43
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,359 ms / 2,000 ms
コード長 735 bytes
コンパイル時間 13,227 ms
コンパイル使用メモリ 425,172 KB
実行使用メモリ 72,464 KB
最終ジャッジ日時 2023-09-29 20:57:37
合計ジャッジ時間 30,316 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 299 ms
56,936 KB
testcase_01 AC 299 ms
59,108 KB
testcase_02 AC 299 ms
56,972 KB
testcase_03 AC 283 ms
52,832 KB
testcase_04 AC 297 ms
56,864 KB
testcase_05 AC 299 ms
56,936 KB
testcase_06 AC 282 ms
53,020 KB
testcase_07 AC 297 ms
56,972 KB
testcase_08 AC 297 ms
56,880 KB
testcase_09 AC 298 ms
56,880 KB
testcase_10 AC 350 ms
57,152 KB
testcase_11 AC 349 ms
57,148 KB
testcase_12 AC 310 ms
57,260 KB
testcase_13 AC 344 ms
57,424 KB
testcase_14 AC 350 ms
57,032 KB
testcase_15 AC 1,166 ms
69,448 KB
testcase_16 AC 815 ms
65,116 KB
testcase_17 AC 1,120 ms
69,856 KB
testcase_18 AC 826 ms
64,136 KB
testcase_19 AC 1,327 ms
72,408 KB
testcase_20 AC 1,349 ms
72,464 KB
testcase_21 AC 1,350 ms
71,540 KB
testcase_22 AC 1,252 ms
71,640 KB
testcase_23 AC 1,359 ms
71,452 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:19:13: 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(ans)
            ^

ソースコード

diff #

import java.util.*

fun main() {
    val builder = StringBuilder()

    readInputLine()

    val aList = readInputLine().split(" ").map { it.toInt() }.sorted()
    val bArr = readInputLine().split(" ").map { it.toInt() }.toIntArray()
    val bListSorted = mutableListOf<Int>()

    var ans = 0L

    for ((i, a) in aList.withIndex()) {
        bListSorted.add(lowerBound(bListSorted, bArr[i]), bArr[i])
        ans += lowerBound(bListSorted, a).toLong()
    }

    builder.appendln(ans)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}

fun <T: Comparable<T>> lowerBound(list: List<T>, value: T): Int {
    return Collections.binarySearch(list, value, { x, y -> if (x >= y) 1 else -1}).inv()
}
0