結果
| 問題 | No.365 ジェンガソート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-10 19:15:07 |
| 言語 | Kotlin (2.3.20) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 709 bytes |
| 記録 | |
| コンパイル時間 | 9,906 ms |
| コンパイル使用メモリ | 454,664 KB |
| 実行使用メモリ | 77,744 KB |
| 最終ジャッジ日時 | 2026-03-29 23:30:00 |
| 合計ジャッジ時間 | 23,189 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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
}
}