結果

問題 No.1804 Intersection of LIS
ユーザー yudedakoyudedako
提出日時 2022-04-18 12:37:30
言語 Kotlin
(1.9.23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,409 bytes
コンパイル時間 15,311 ms
コンパイル使用メモリ 421,776 KB
実行使用メモリ 84,436 KB
最終ジャッジ日時 2023-08-27 22:35:27
合計ジャッジ時間 44,244 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 307 ms
57,164 KB
testcase_01 AC 310 ms
57,012 KB
testcase_02 AC 295 ms
53,176 KB
testcase_03 AC 924 ms
83,496 KB
testcase_04 AC 924 ms
84,200 KB
testcase_05 AC 926 ms
83,956 KB
testcase_06 AC 925 ms
83,568 KB
testcase_07 AC 924 ms
84,124 KB
testcase_08 AC 923 ms
83,880 KB
testcase_09 AC 935 ms
84,400 KB
testcase_10 AC 923 ms
84,304 KB
testcase_11 AC 934 ms
83,520 KB
testcase_12 AC 936 ms
83,952 KB
testcase_13 AC 925 ms
83,512 KB
testcase_14 AC 934 ms
83,736 KB
testcase_15 AC 949 ms
83,712 KB
testcase_16 AC 926 ms
84,436 KB
testcase_17 AC 918 ms
83,880 KB
testcase_18 AC 355 ms
57,480 KB
testcase_19 AC 357 ms
57,476 KB
testcase_20 AC 357 ms
57,844 KB
testcase_21 AC 355 ms
57,512 KB
testcase_22 AC 357 ms
57,480 KB
testcase_23 AC 357 ms
57,572 KB
testcase_24 AC 357 ms
57,536 KB
testcase_25 AC 357 ms
57,444 KB
testcase_26 AC 356 ms
57,624 KB
testcase_27 AC 354 ms
57,516 KB
testcase_28 AC 306 ms
57,044 KB
testcase_29 AC 306 ms
57,108 KB
testcase_30 AC 306 ms
57,220 KB
testcase_31 AC 293 ms
53,428 KB
testcase_32 AC 309 ms
57,188 KB
testcase_33 AC 293 ms
53,180 KB
testcase_34 AC 310 ms
57,372 KB
testcase_35 TLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

fun createLIS(permutation: List<Int>): List<Int> {
    val minLast = IntArray(permutation.size + 1){permutation.size + 1}.also { it[0] = 0 }
    val prevValue = IntArray(permutation.size + 1)
    for (a in permutation) {
        val pos = minLast.lowerBound(a)
        prevValue[a] = minLast[pos - 1]
        minLast[pos] = a
    }
    val result = mutableListOf<Int>((minLast.last { it != permutation.size + 1 }))
    while (result.last() > 0) {
        result.add(prevValue[result.last()])
    }
    result.removeLast()
    return result.reversed()
}
inline fun IntArray.partitionPoint(predicate: (Int) -> Boolean): Int {
    var min = 0
    var max = size
    while (min < max) {
        val mid = (min + max) / 2
        if (predicate(this[mid])) {
            min = mid + 1
        }else {
            max = mid
        }
    }
    return max
}
fun IntArray.lowerBound(target: Int): Int {
    return partitionPoint { it < target }
}
fun main() {
    System.setProperty("kotlin.collections.convert_arg_to_set_in_removeAll", "true")
    val n = readLine()!!.trim().toInt()
    val permutation = readLine()!!.trim().split(' ').map(String::toInt)
    val forward = createLIS(permutation)
    val backward = createLIS(permutation.reversed().map { n - it + 1 }).reversed().map { n - it + 1 }
    val fix = forward.intersect(backward)
    println(fix.size)
    println(fix.toList().sorted().joinToString(" "))
}
0