結果
問題 | No.992 最長増加部分列の数え上げ |
ユーザー | yakamoto |
提出日時 | 2020-02-14 22:46:56 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 1,331 ms / 2,000 ms |
コード長 | 3,600 bytes |
コンパイル時間 | 16,585 ms |
コンパイル使用メモリ | 453,768 KB |
実行使用メモリ | 127,292 KB |
最終ジャッジ日時 | 2024-10-06 13:05:57 |
合計ジャッジ時間 | 60,807 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 329 ms
59,880 KB |
testcase_01 | AC | 323 ms
59,852 KB |
testcase_02 | AC | 329 ms
59,976 KB |
testcase_03 | AC | 329 ms
59,944 KB |
testcase_04 | AC | 834 ms
97,032 KB |
testcase_05 | AC | 796 ms
95,388 KB |
testcase_06 | AC | 904 ms
105,720 KB |
testcase_07 | AC | 817 ms
97,920 KB |
testcase_08 | AC | 700 ms
79,952 KB |
testcase_09 | AC | 819 ms
97,292 KB |
testcase_10 | AC | 913 ms
107,912 KB |
testcase_11 | AC | 1,003 ms
109,744 KB |
testcase_12 | AC | 624 ms
75,888 KB |
testcase_13 | AC | 845 ms
95,568 KB |
testcase_14 | AC | 835 ms
97,428 KB |
testcase_15 | AC | 641 ms
78,704 KB |
testcase_16 | AC | 1,136 ms
123,156 KB |
testcase_17 | AC | 701 ms
84,636 KB |
testcase_18 | AC | 809 ms
95,664 KB |
testcase_19 | AC | 941 ms
110,448 KB |
testcase_20 | AC | 1,205 ms
125,424 KB |
testcase_21 | AC | 1,181 ms
125,452 KB |
testcase_22 | AC | 1,220 ms
125,040 KB |
testcase_23 | AC | 1,208 ms
125,392 KB |
testcase_24 | AC | 1,194 ms
125,364 KB |
testcase_25 | AC | 1,226 ms
125,536 KB |
testcase_26 | AC | 1,331 ms
127,136 KB |
testcase_27 | AC | 1,223 ms
125,308 KB |
testcase_28 | AC | 1,212 ms
123,956 KB |
testcase_29 | AC | 1,286 ms
127,292 KB |
testcase_30 | AC | 1,018 ms
124,552 KB |
testcase_31 | AC | 1,021 ms
124,456 KB |
testcase_32 | AC | 975 ms
123,696 KB |
testcase_33 | AC | 986 ms
125,212 KB |
testcase_34 | AC | 990 ms
125,772 KB |
testcase_35 | AC | 856 ms
115,924 KB |
testcase_36 | AC | 905 ms
115,820 KB |
testcase_37 | AC | 866 ms
115,932 KB |
testcase_38 | AC | 844 ms
115,828 KB |
testcase_39 | AC | 877 ms
115,780 KB |
testcase_40 | AC | 1,027 ms
123,844 KB |
testcase_41 | AC | 1,040 ms
123,620 KB |
testcase_42 | AC | 1,059 ms
124,148 KB |
testcase_43 | AC | 1,059 ms
123,116 KB |
testcase_44 | AC | 1,069 ms
122,480 KB |
ソースコード
import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.util.* import kotlin.math.abs import kotlin.math.max import kotlin.math.min val MOD = 1_000_000_007 class Solver(stream: InputStream, private val out: java.io.PrintWriter) { fun solve() { val N = ni() val A = na(N) val (ix, pos) = LIS(A, N) debug{ix.joinToString { it.toString() }} debug(pos) val C = Array(ix.size){ BIT(ix[it].size) } for (i in 0 until N) { val p = pos[i] val cnt = if (p == 0) 1 else C[p-1].sum(ix[p-1][i]!!) debug{"$cnt"} C[p].add(ix[p][i]!!, cnt) } val ans = C[ix.lastIndex].sum(ix.last().size) out.println(ans) } fun LIS(A: IntArray, N: Int): Pair<Array<MutableMap<Int, Int>>, IntArray> { val ix = Array(N){ mutableListOf<Int>()} val lis = IntArray(N) var p = 0 val pos = IntArray(N) for (i in 0 until A.size) { var l = -1 var h = p while(h - l > 1) { val m = (h + l) / 2 if (lis[m] >= A[i]) h = m else l = m } lis[h] = A[i] ix[h].add(i) if (h > 0) ix[h-1].add(i) p = max(p, h + 1) pos[i] = h } val ix2 = Array(p){ mutableMapOf<Int, Int>() } for (i in 0 until p) { ix[i].sortWith(compareBy({A[it]}, {-it})) for (j in 0 until ix[i].size) { ix2[i][ix[i][j]] = j } } return Pair(ix2, pos) } class BIT(n: Int) { private val N = if (Integer.highestOneBit(n) == n) n else Integer.highestOneBit(n) shl 1 private val bit = LongArray(N + 1) fun sum(i: Int): Long { var x = i var s = 0L while(x > 0) { s += bit[x] x -= x and -x } return s % MOD } fun add(i: Int, a: Long) { var x = i + 1 while(x <= N) { bit[x] = (bit[x] + a) % MOD x += x and -x } } } private val isDebug = try { // なんか本番でエラーでる System.getenv("MY_DEBUG") != null } catch (t: Throwable) { false } private var tokenizer: StringTokenizer? = null private val reader = BufferedReader(InputStreamReader(stream), 32768) private fun next(): String { while (tokenizer == null || !tokenizer!!.hasMoreTokens()) { tokenizer = StringTokenizer(reader.readLine()) } return tokenizer!!.nextToken() } private fun ni() = next().toInt() private fun nl() = next().toLong() private fun ns() = next() private fun na(n: Int, offset: Int = 0): IntArray { return map(n, offset) { ni() } } private inline fun map(n: Int, offset: Int = 0, f: (Int) -> Int): IntArray { val res = IntArray(n) for (i in 0 until n) { res[i] = f(i + offset) } return res } private inline fun debug(msg: () -> String) { if (isDebug) System.err.println(msg()) } private fun debug(a: LongArray) { debug { a.joinToString(" ") } } private fun debug(a: IntArray) { debug { a.joinToString(" ") } } private fun debug(a: BooleanArray) { debug { a.map { if (it) 1 else 0 }.joinToString("") } } private fun debugDim(A: Array<IntArray>) { if (isDebug) { for (a in A) { debug(a) } } } /** * 勝手にimport消されるのを防ぎたい */ private fun hoge() { min(1, 2) max(1, 2) abs(-10) } } fun <A, B> pair(a: A, b: B) = RPair(a, b) data class RPair<A, B>(val _1: A, val _2: B) fun main() { val out = java.io.PrintWriter(System.out) Solver(System.`in`, out).solve() out.flush() }