結果

問題 No.365 ジェンガソート
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2021-02-10 19:15:07
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 709 bytes
コンパイル時間 13,925 ms
コンパイル使用メモリ 426,816 KB
実行使用メモリ 60,420 KB
最終ジャッジ日時 2023-09-22 14:25:38
合計ジャッジ時間 32,783 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 286 ms
53,064 KB
testcase_01 AC 283 ms
53,056 KB
testcase_02 AC 286 ms
52,916 KB
testcase_03 AC 281 ms
52,924 KB
testcase_04 AC 280 ms
53,312 KB
testcase_05 AC 283 ms
52,884 KB
testcase_06 AC 282 ms
53,048 KB
testcase_07 AC 290 ms
53,300 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 283 ms
53,284 KB
testcase_15 AC 289 ms
52,972 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 382 ms
55,612 KB
testcase_19 AC 501 ms
60,420 KB
testcase_20 AC 451 ms
57,808 KB
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 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 487 ms
59,796 KB
testcase_37 AC 494 ms
59,900 KB
testcase_38 WA -
testcase_39 AC 519 ms
60,260 KB
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }

    val bit = Bit(n+1)
    var ans = 0
    for ((i, ai) in a.withIndex()) {
        if (i - bit.sum(ai) > 0) ans++
        bit.add(ai)
    }
    println(ans)
}

data class Bit(private val n : Int) {
    private val bit = Array(n+1) { 0 }

    fun add(i : Int) {
        var index = i + 1
        while (index <= n) {
            bit[index] += 1
            index += index and -index
        }
    }

    fun sum(i : Int): Int {
        var res = 0
        var index = i + 1
        while (index > 0) {
            res += bit[index]
            index -= index and -index
        }
        return res
    }
}
0