結果
問題 | No.848 なかよし旅行 |
ユーザー | pekempey |
提出日時 | 2019-07-25 07:16:43 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 808 ms / 2,000 ms |
コード長 | 2,266 bytes |
コンパイル時間 | 15,842 ms |
コンパイル使用メモリ | 452,388 KB |
実行使用メモリ | 95,316 KB |
最終ジャッジ日時 | 2024-11-08 01:07:28 |
合計ジャッジ時間 | 30,348 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 808 ms
95,316 KB |
testcase_01 | AC | 314 ms
54,540 KB |
testcase_02 | AC | 306 ms
54,396 KB |
testcase_03 | AC | 308 ms
54,500 KB |
testcase_04 | AC | 311 ms
54,424 KB |
testcase_05 | AC | 309 ms
54,440 KB |
testcase_06 | AC | 319 ms
54,744 KB |
testcase_07 | AC | 326 ms
54,504 KB |
testcase_08 | AC | 333 ms
54,756 KB |
testcase_09 | AC | 345 ms
54,868 KB |
testcase_10 | AC | 343 ms
54,764 KB |
testcase_11 | AC | 510 ms
61,500 KB |
testcase_12 | AC | 518 ms
61,964 KB |
testcase_13 | AC | 571 ms
63,960 KB |
testcase_14 | AC | 443 ms
56,748 KB |
testcase_15 | AC | 565 ms
63,580 KB |
testcase_16 | AC | 607 ms
66,340 KB |
testcase_17 | AC | 617 ms
63,436 KB |
testcase_18 | AC | 538 ms
60,436 KB |
testcase_19 | AC | 512 ms
60,512 KB |
testcase_20 | AC | 401 ms
55,700 KB |
testcase_21 | AC | 599 ms
64,416 KB |
testcase_22 | AC | 524 ms
65,368 KB |
testcase_23 | AC | 411 ms
55,540 KB |
testcase_24 | AC | 307 ms
54,488 KB |
testcase_25 | AC | 622 ms
66,580 KB |
testcase_26 | AC | 312 ms
54,388 KB |
testcase_27 | AC | 313 ms
54,420 KB |
testcase_28 | AC | 318 ms
54,516 KB |
testcase_29 | AC | 310 ms
54,380 KB |
コンパイルメッセージ
Main.kt:59:16: warning: 'toInt(): Int' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead. while ('0'.toInt() > peek()) next(); ^ Main.kt:60:16: warning: 'toInt(): Int' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead. while ('0'.toInt() <= peek()) { ^ Main.kt:61: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:72: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 { if (d != other.d) return d.compareTo(other.d) return u.compareTo(other.u) } } 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, {0}) var k: Int = 0 var n: Int = 0 private fun check() { if (k == n) { n = System.`in`.read(buf) k = 0 } } private fun peek(): Byte { check() return buf[k] } fun next() { k++ check() } fun long(): Long { var ans: Long = 0 while ('0'.toInt() > peek()) next(); while ('0'.toInt() <= 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 start = System.currentTimeMillis() 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 end = System.currentTimeMillis() System.err.println(end - start) val d0 = dijkstra(g, 0) val dp = dijkstra(g, P) val dq = dijkstra(g, Q) 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])) } } } if (ans < 0L) { println(-1) } else { println(ans) } }