結果
問題 | No.1607 Kth Maximum Card |
ユーザー | yakamoto |
提出日時 | 2021-07-16 23:12:59 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 3,196 ms / 3,500 ms |
コード長 | 4,371 bytes |
コンパイル時間 | 18,063 ms |
コンパイル使用メモリ | 443,060 KB |
実行使用メモリ | 128,588 KB |
最終ジャッジ日時 | 2023-09-20 15:41:32 |
合計ジャッジ時間 | 60,084 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 281 ms
53,720 KB |
testcase_01 | AC | 279 ms
53,828 KB |
testcase_02 | AC | 281 ms
54,052 KB |
testcase_03 | AC | 281 ms
53,784 KB |
testcase_04 | AC | 283 ms
53,988 KB |
testcase_05 | AC | 280 ms
53,808 KB |
testcase_06 | AC | 281 ms
53,868 KB |
testcase_07 | AC | 282 ms
53,864 KB |
testcase_08 | AC | 2,733 ms
123,528 KB |
testcase_09 | AC | 899 ms
83,832 KB |
testcase_10 | AC | 834 ms
86,120 KB |
testcase_11 | AC | 615 ms
65,488 KB |
testcase_12 | AC | 915 ms
80,412 KB |
testcase_13 | AC | 807 ms
65,688 KB |
testcase_14 | AC | 877 ms
69,548 KB |
testcase_15 | AC | 2,318 ms
118,332 KB |
testcase_16 | AC | 569 ms
61,488 KB |
testcase_17 | AC | 578 ms
61,424 KB |
testcase_18 | AC | 1,525 ms
96,420 KB |
testcase_19 | AC | 1,109 ms
80,204 KB |
testcase_20 | AC | 1,366 ms
84,616 KB |
testcase_21 | AC | 1,467 ms
90,288 KB |
testcase_22 | AC | 2,616 ms
128,424 KB |
testcase_23 | AC | 2,569 ms
128,588 KB |
testcase_24 | AC | 1,130 ms
78,368 KB |
testcase_25 | AC | 862 ms
67,604 KB |
testcase_26 | AC | 982 ms
69,928 KB |
testcase_27 | AC | 1,099 ms
79,804 KB |
testcase_28 | AC | 1,074 ms
73,932 KB |
testcase_29 | AC | 770 ms
78,080 KB |
testcase_30 | AC | 3,196 ms
124,724 KB |
testcase_31 | AC | 1,586 ms
95,264 KB |
testcase_32 | AC | 1,347 ms
82,116 KB |
testcase_33 | AC | 1,453 ms
82,008 KB |
testcase_34 | AC | 1,537 ms
82,040 KB |
testcase_35 | AC | 1,326 ms
83,080 KB |
コンパイルメッセージ
Main.kt:180:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debug(a: LongArray) { ^ Main.kt:184:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debug(a: IntArray) { ^ Main.kt:188:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debug(a: BooleanArray) { ^ Main.kt:192:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")} ^ Main.kt:194:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debugDim(A: Array<LongArray>) { ^ Main.kt:201:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debugDim(A: Array<IntArray>) { ^ Main.kt:208:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debugDim(A: Array<BooleanArray>) { ^ Main.kt:225:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()} ^
ソースコード
import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.lang.AssertionError import java.util.* import kotlin.math.abs import kotlin.math.max import kotlin.math.min val MOD = 1_000_000_007 /** * 単調増加 * (l, h] 方式 * @return マッチするものがなかったらmx */ inline fun findMin(mn: Int, mx: Int, f: (Int) -> Boolean): Int { var low = mn - 1 var high = mx while(high - low > 1) { val m = (low + high) / 2 if (f(m)) high = m else low = m } return high } data class Edge(val v: Int, val u: Int, val c: Int) class Solver(stream: InputStream, private val out: java.io.PrintWriter) { private val reader = BufferedReader(InputStreamReader(stream), 32768) private val N = ni() private val M = ni() private val K = ni() private val D = IntArray(N) private val g0 = Array(N){ mutableListOf<Edge>()} val inf = 1e9.toInt() + 100 fun dijk(g: Array<MutableList<Edge>>, s: Int): IntArray { D.fill(inf) D[s] = 0 val que = ArrayDeque<Int>() que.add(s) while(que.isNotEmpty()) { val v = que.poll()!! for (i in 0 until g[v].size) { val e = g[v][i] if (D[v] + e.c < D[e.u]) { D[e.u] = D[v] + e.c if (e.c == 0) que.addFirst(e.u) else que.addLast(e.u) } } } return D } fun solve() { val E = Array(M){ val (v, u) = na(2, -1) val c = ni() Edge(v, u, c) } fun calc(x: Int): IntArray { for (i in 0 until N) { g0[i].clear() } for (i in E) { val c = if (i.c > x) 1 else 0 g0[i.v].add(Edge(i.v, i.u, c)) g0[i.u].add(Edge(i.u, i.v, c)) } return dijk(g0, 0) } // K進むことなくNに到達できる if (calc(0)[N - 1] < K) { out.println(0) return } val ans = findMin(1, 200_000) { x -> val D = calc(x) D[N - 1] <= K - 1 } out.println(ans) } private val isDebug = try { // なんか本番でエラーでる System.getenv("MY_DEBUG") != null } catch (t: Throwable) { false } private var tokenizer: StringTokenizer? = null 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 IntArray(n) { ni() + offset } } private fun nal(n: Int, offset: Int = 0): LongArray { val res = LongArray(n) for (i in 0 until n) { res[i] = nl() + offset } return res } private fun na2(n: Int, offset: Int = 0): Array<IntArray> { val a = Array(2){IntArray(n)} for (i in 0 until n) { for (e in a) { e[i] = ni() + offset } } return a } private inline fun debug(msg: () -> String) { if (isDebug) System.err.println(msg()) } /** * コーナーケースでエラー出たりするので、debug(dp[1])のように添え字付きの場合はdebug{}をつかうこと */ private inline fun debug(a: LongArray) { debug { a.joinToString(" ") } } private inline fun debug(a: IntArray) { debug { a.joinToString(" ") } } private inline fun debug(a: BooleanArray) { debug { toString(a) } } private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")} private inline fun debugDim(A: Array<LongArray>) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array<IntArray>) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array<BooleanArray>) { if (isDebug) { for (a in A) { debug(a) } } } /** * 勝手にimport消されるのを防ぎたい */ private fun hoge() { min(1, 2) max(1, 2) abs(-10) } private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()} private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())} } fun main() { val out = java.io.PrintWriter(System.out) Solver(System.`in`, out).solve() out.flush() }