結果
問題 | No.848 なかよし旅行 |
ユーザー | pekempey |
提出日時 | 2019-07-25 07:26:06 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 813 ms / 2,000 ms |
コード長 | 2,244 bytes |
コンパイル時間 | 15,249 ms |
コンパイル使用メモリ | 463,868 KB |
実行使用メモリ | 95,616 KB |
最終ジャッジ日時 | 2024-11-08 01:06:13 |
合計ジャッジ時間 | 30,798 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 813 ms
95,616 KB |
testcase_01 | AC | 302 ms
54,648 KB |
testcase_02 | AC | 303 ms
54,444 KB |
testcase_03 | AC | 299 ms
54,636 KB |
testcase_04 | AC | 297 ms
54,728 KB |
testcase_05 | AC | 300 ms
54,424 KB |
testcase_06 | AC | 307 ms
54,728 KB |
testcase_07 | AC | 305 ms
54,800 KB |
testcase_08 | AC | 318 ms
54,676 KB |
testcase_09 | AC | 329 ms
54,940 KB |
testcase_10 | AC | 316 ms
54,948 KB |
testcase_11 | AC | 502 ms
61,028 KB |
testcase_12 | AC | 485 ms
61,764 KB |
testcase_13 | AC | 536 ms
63,744 KB |
testcase_14 | AC | 419 ms
56,716 KB |
testcase_15 | AC | 555 ms
63,444 KB |
testcase_16 | AC | 592 ms
66,196 KB |
testcase_17 | AC | 585 ms
63,160 KB |
testcase_18 | AC | 532 ms
60,780 KB |
testcase_19 | AC | 500 ms
60,760 KB |
testcase_20 | AC | 394 ms
55,568 KB |
testcase_21 | AC | 570 ms
64,184 KB |
testcase_22 | AC | 509 ms
65,448 KB |
testcase_23 | AC | 398 ms
55,804 KB |
testcase_24 | AC | 297 ms
54,520 KB |
testcase_25 | AC | 688 ms
67,680 KB |
testcase_26 | AC | 299 ms
54,512 KB |
testcase_27 | AC | 307 ms
54,548 KB |
testcase_28 | AC | 295 ms
54,412 KB |
testcase_29 | AC | 300 ms
54,508 KB |
コンパイルメッセージ
Main.kt:61:16: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead. while ('0'.toByte() > peek()) next() ^ Main.kt:62:16: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead. while ('0'.toByte() <= peek()) { ^ Main.kt:63:38: warning: 'toLong(): Long' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead. ans = ans * 10 + (peek() - '0'.toLong()) ^ Main.kt:74:10: warning: parameter 'args' is never used fun main(args: Array<String>) { ^
ソースコード
import java.util.PriorityQueue import java.util.Scanner import java.io.BufferedReader import java.io.InputStreamReader data class Edge(val v: Int, val w: Long) val INF = 1e18.toLong() fun dijkstra(g: Array<MutableList<Edge>>, s: Int): Array<Long> { data class State(val d: Long, val u: Int) : Comparable<State> { override operator fun compareTo(other: State): Int { return d.compareTo(other.d) } } var q: PriorityQueue<State> = PriorityQueue() val n = g.size var dist = Array(n, {INF}) dist[s] = 0 q.add(State(0, s)) while (!q.isEmpty()) { val (d, u) = q.remove() if (d > dist[u]) continue for (e in g[u]) { if (dist[e.v] > dist[u] + e.w) { dist[e.v] = dist[u] + e.w q.add(State(dist[e.v], e.v)) } } } return dist } class Reader { var buf: ByteArray = ByteArray(5000000) var k: Int = 0 var n: Int = 0 init { check() } private fun check() { if (k == n) { n = System.`in`.read(buf) k = 0 } } private fun peek(): Byte { return buf[k] } private fun next() { k++ check() } fun long(): Long { var ans: Long = 0 while ('0'.toByte() > peek()) next() while ('0'.toByte() <= peek()) { ans = ans * 10 + (peek() - '0'.toLong()) next() } return ans } fun int(): Int { return long().toInt() } } fun main(args: Array<String>) { var r = Reader() val N = r.int() val M = r.int() val P = r.int() - 1 val Q = r.int() - 1 val T = r.long() var g = Array(N, {mutableListOf<Edge>()}) repeat(M) { val u = r.int() - 1 val v = r.int() - 1 val w = r.long() g[u].add(Edge(v, w)) g[v].add(Edge(u, w)) } val start = System.currentTimeMillis() val d0 = dijkstra(g, 0) val dp = dijkstra(g, P) val dq = dijkstra(g, Q) val end = System.currentTimeMillis() var ans = -INF if (dp[0] + dp[Q] + dq[0] <= T) { ans = T } for (i in 0..N-1) { for (j in 0..N-1) { if (d0[i] + d0[j] + maxOf(dp[i] + dp[j], dq[i] + dq[j]) <= T) { ans = maxOf(ans, T - maxOf(dp[i] + dp[j], dq[i] + dq[j])) } } } System.err.println(end - start) if (ans < 0L) { println(-1) } else { println(ans) } }