結果
問題 | No.848 なかよし旅行 |
ユーザー | pekempey |
提出日時 | 2019-07-25 06:59:14 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 868 ms / 2,000 ms |
コード長 | 2,067 bytes |
コンパイル時間 | 17,749 ms |
コンパイル使用メモリ | 457,884 KB |
実行使用メモリ | 90,116 KB |
最終ジャッジ日時 | 2024-11-08 01:09:47 |
合計ジャッジ時間 | 32,049 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 868 ms
90,116 KB |
testcase_01 | AC | 331 ms
59,588 KB |
testcase_02 | AC | 323 ms
59,632 KB |
testcase_03 | AC | 319 ms
59,576 KB |
testcase_04 | AC | 324 ms
59,624 KB |
testcase_05 | AC | 324 ms
59,520 KB |
testcase_06 | AC | 333 ms
59,744 KB |
testcase_07 | AC | 326 ms
59,616 KB |
testcase_08 | AC | 343 ms
59,956 KB |
testcase_09 | AC | 353 ms
59,852 KB |
testcase_10 | AC | 344 ms
59,984 KB |
testcase_11 | AC | 557 ms
67,080 KB |
testcase_12 | AC | 586 ms
68,756 KB |
testcase_13 | AC | 679 ms
71,488 KB |
testcase_14 | AC | 531 ms
65,032 KB |
testcase_15 | AC | 661 ms
70,972 KB |
testcase_16 | AC | 718 ms
74,400 KB |
testcase_17 | AC | 644 ms
71,248 KB |
testcase_18 | AC | 560 ms
67,264 KB |
testcase_19 | AC | 577 ms
66,724 KB |
testcase_20 | AC | 440 ms
60,964 KB |
testcase_21 | AC | 651 ms
72,536 KB |
testcase_22 | AC | 548 ms
72,652 KB |
testcase_23 | AC | 457 ms
60,856 KB |
testcase_24 | AC | 323 ms
59,588 KB |
testcase_25 | AC | 684 ms
75,412 KB |
testcase_26 | AC | 319 ms
59,684 KB |
testcase_27 | AC | 324 ms
59,560 KB |
testcase_28 | AC | 321 ms
59,564 KB |
testcase_29 | AC | 322 ms
59,432 KB |
コンパイルメッセージ
Main.kt:35:10: warning: parameter 'args' is never used fun main(args: Array<String>) { ^ Main.kt:41:16: warning: 'toInt(): Int' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead. while ('0'.toInt() > buf[bufk]) bufk++; ^ Main.kt:42:16: warning: 'toInt(): Int' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead. while ('0'.toInt() <= buf[bufk]) { ^ Main.kt:43:41: warning: 'toLong(): Long' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead. ans = ans * 10 + (buf[bufk] - '0'.toLong()) ^
ソースコード
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 } fun main(args: Array<String>) { var buf: ByteArray = ByteArray(10000000, {0}) System.`in`.read(buf) var bufk = 0 val readLong = fun(): Long { var ans: Long = 0 while ('0'.toInt() > buf[bufk]) bufk++; while ('0'.toInt() <= buf[bufk]) { ans = ans * 10 + (buf[bufk] - '0'.toLong()) bufk++; } return ans } val readInt = fun(): Int = readLong().toInt() val start = System.currentTimeMillis() val N = readInt() val M = readInt() val P = readInt() - 1 val Q = readInt() - 1 val T = readLong() var g = Array(N, {mutableListOf<Edge>()}) repeat(M) { val u = readInt() - 1 val v = readInt() - 1 val w = readLong() 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) } }