結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー rutilicusrutilicus
提出日時 2020-12-19 21:33:50
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 654 ms / 2,000 ms
コード長 1,111 bytes
コンパイル時間 18,209 ms
コンパイル使用メモリ 436,096 KB
実行使用メモリ 68,424 KB
最終ジャッジ日時 2023-10-21 09:38:56
合計ジャッジ時間 36,356 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 420 ms
59,752 KB
testcase_01 AC 277 ms
54,532 KB
testcase_02 AC 282 ms
54,544 KB
testcase_03 AC 606 ms
63,796 KB
testcase_04 AC 639 ms
67,332 KB
testcase_05 AC 591 ms
63,880 KB
testcase_06 AC 579 ms
63,792 KB
testcase_07 AC 634 ms
67,968 KB
testcase_08 AC 411 ms
59,020 KB
testcase_09 AC 550 ms
67,920 KB
testcase_10 AC 605 ms
67,980 KB
testcase_11 AC 293 ms
54,536 KB
testcase_12 AC 623 ms
66,960 KB
testcase_13 AC 645 ms
68,396 KB
testcase_14 AC 637 ms
68,424 KB
testcase_15 AC 279 ms
54,540 KB
testcase_16 AC 280 ms
54,540 KB
testcase_17 AC 301 ms
54,528 KB
testcase_18 AC 307 ms
54,588 KB
testcase_19 AC 290 ms
54,604 KB
testcase_20 AC 277 ms
54,556 KB
testcase_21 AC 296 ms
54,524 KB
testcase_22 AC 283 ms
54,544 KB
testcase_23 AC 435 ms
59,880 KB
testcase_24 AC 506 ms
61,512 KB
testcase_25 AC 575 ms
63,868 KB
testcase_26 AC 454 ms
61,152 KB
testcase_27 AC 536 ms
61,460 KB
testcase_28 AC 574 ms
67,876 KB
testcase_29 AC 613 ms
63,064 KB
testcase_30 AC 654 ms
68,272 KB
testcase_31 AC 495 ms
60,432 KB
testcase_32 AC 465 ms
61,160 KB
testcase_33 AC 603 ms
61,860 KB
testcase_34 AC 275 ms
54,544 KB
testcase_35 AC 281 ms
54,532 KB
testcase_36 AC 278 ms
54,536 KB
testcase_37 AC 283 ms
54,540 KB
testcase_38 AC 292 ms
54,536 KB
testcase_39 AC 285 ms
54,540 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:18: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(mergeCount(bArr))
            ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()

    val num2Index = IntArray(n + 1)

    readInputLine().split(" ").mapIndexed { index, s ->
        num2Index[s.toInt()] = index
    }

    val bArr = readInputLine().split(" ").map { it.toInt() }.toIntArray()

    bArr.forEachIndexed { index, i ->
        bArr[index] = num2Index[i]
    }

    builder.appendln(mergeCount(bArr))

    print(builder.toString())
}

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

fun mergeCount(arr: IntArray): Long {
    val n = arr.size
    if (n <= 1L) {
        return 0L
    }
    val b = IntArray(n / 2) { arr[it] }
    val c = IntArray(arr.size - (n / 2)) { arr[it + n / 2] }

    var count = 0L
    count += mergeCount(b)
    count += mergeCount(c)
    var ai = 0
    var bi = 0
    var ci = 0
    while (ai < n) {
        if (bi < b.size && (ci == c.size || b[bi] <= c[ci])) {
            arr[ai] = b[bi]
            bi++
        } else {
            count += (n / 2 - bi).toLong()
            arr[ai] = c[ci]
            ci++
        }
        ai++
    }
    return count
}
0