結果
問題 |
No.365 ジェンガソート
|
ユーザー |
|
提出日時 | 2021-02-10 19:15:07 |
言語 | Kotlin (2.1.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 709 bytes |
コンパイル時間 | 11,857 ms |
コンパイル使用メモリ | 443,424 KB |
実行使用メモリ | 71,148 KB |
最終ジャッジ日時 | 2024-07-08 06:01:44 |
合計ジャッジ時間 | 27,009 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 25 |
ソースコード
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 } }