結果
問題 |
No.1804 Intersection of LIS
|
ユーザー |
|
提出日時 | 2022-04-18 12:37:30 |
言語 | Kotlin (2.1.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,409 bytes |
コンパイル時間 | 22,064 ms |
コンパイル使用メモリ | 439,484 KB |
実行使用メモリ | 217,876 KB |
最終ジャッジ日時 | 2024-12-28 07:38:57 |
合計ジャッジ時間 | 50,057 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 TLE * 2 |
ソースコード
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(" ")) }