結果

問題 No.1804 Intersection of LIS
ユーザー yudedakoyudedako
提出日時 2022-01-09 23:45:46
言語 Kotlin
(1.9.23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,325 bytes
コンパイル時間 14,881 ms
コンパイル使用メモリ 440,632 KB
実行使用メモリ 123,364 KB
最終ジャッジ日時 2024-04-26 19:58:07
合計ジャッジ時間 39,739 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 315 ms
58,620 KB
testcase_01 AC 316 ms
91,024 KB
testcase_02 AC 307 ms
57,312 KB
testcase_03 AC 881 ms
99,752 KB
testcase_04 AC 843 ms
99,744 KB
testcase_05 AC 868 ms
99,656 KB
testcase_06 AC 836 ms
99,780 KB
testcase_07 AC 835 ms
99,736 KB
testcase_08 AC 838 ms
99,480 KB
testcase_09 AC 838 ms
99,712 KB
testcase_10 AC 831 ms
99,636 KB
testcase_11 AC 858 ms
99,796 KB
testcase_12 AC 882 ms
99,632 KB
testcase_13 AC 828 ms
99,880 KB
testcase_14 AC 883 ms
99,920 KB
testcase_15 AC 876 ms
99,464 KB
testcase_16 AC 830 ms
99,624 KB
testcase_17 AC 850 ms
99,768 KB
testcase_18 AC 373 ms
55,912 KB
testcase_19 AC 369 ms
55,876 KB
testcase_20 AC 367 ms
55,996 KB
testcase_21 AC 371 ms
55,764 KB
testcase_22 AC 364 ms
55,916 KB
testcase_23 AC 368 ms
55,672 KB
testcase_24 AC 366 ms
55,648 KB
testcase_25 AC 376 ms
55,684 KB
testcase_26 AC 363 ms
55,672 KB
testcase_27 AC 366 ms
55,808 KB
testcase_28 AC 319 ms
55,036 KB
testcase_29 AC 313 ms
54,764 KB
testcase_30 AC 315 ms
54,964 KB
testcase_31 AC 315 ms
51,652 KB
testcase_32 AC 311 ms
55,064 KB
testcase_33 AC 300 ms
51,904 KB
testcase_34 AC 304 ms
54,836 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() {
    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