結果
問題 | No.1545 [Cherry 2nd Tune N] Anthem |
ユーザー | ks2m |
提出日時 | 2021-06-11 23:04:21 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,787 bytes |
コンパイル時間 | 2,666 ms |
コンパイル使用メモリ | 80,464 KB |
実行使用メモリ | 75,708 KB |
最終ジャッジ日時 | 2024-05-08 19:17:34 |
合計ジャッジ時間 | 30,863 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
36,676 KB |
testcase_01 | AC | 50 ms
37,336 KB |
testcase_02 | AC | 50 ms
36,900 KB |
testcase_03 | AC | 51 ms
37,016 KB |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | AC | 272 ms
46,060 KB |
testcase_25 | AC | 178 ms
42,040 KB |
testcase_26 | AC | 60 ms
37,352 KB |
testcase_27 | AC | 136 ms
41,052 KB |
testcase_28 | AC | 265 ms
46,044 KB |
testcase_29 | AC | 271 ms
46,508 KB |
testcase_30 | AC | 219 ms
44,096 KB |
testcase_31 | AC | 209 ms
45,208 KB |
testcase_32 | AC | 128 ms
40,252 KB |
testcase_33 | AC | 246 ms
46,064 KB |
testcase_34 | AC | 200 ms
43,052 KB |
testcase_35 | AC | 283 ms
46,344 KB |
testcase_36 | AC | 277 ms
46,360 KB |
testcase_37 | AC | 135 ms
40,064 KB |
testcase_38 | AC | 200 ms
42,924 KB |
testcase_39 | AC | 126 ms
40,672 KB |
testcase_40 | AC | 180 ms
42,168 KB |
testcase_41 | AC | 95 ms
38,456 KB |
testcase_42 | AC | 219 ms
43,684 KB |
testcase_43 | AC | 258 ms
46,252 KB |
testcase_44 | AC | 101 ms
39,560 KB |
testcase_45 | AC | 56 ms
38,316 KB |
testcase_46 | AC | 141 ms
44,056 KB |
testcase_47 | AC | 155 ms
44,700 KB |
testcase_48 | AC | 164 ms
47,572 KB |
testcase_49 | AC | 196 ms
47,008 KB |
testcase_50 | AC | 270 ms
49,020 KB |
testcase_51 | AC | 98 ms
40,228 KB |
testcase_52 | AC | 290 ms
48,664 KB |
testcase_53 | AC | 171 ms
46,864 KB |
testcase_54 | AC | 112 ms
40,968 KB |
testcase_55 | AC | 244 ms
47,968 KB |
testcase_56 | AC | 102 ms
39,796 KB |
testcase_57 | AC | 217 ms
47,264 KB |
testcase_58 | AC | 185 ms
47,060 KB |
testcase_59 | AC | 117 ms
42,492 KB |
testcase_60 | AC | 109 ms
42,272 KB |
testcase_61 | AC | 149 ms
44,296 KB |
testcase_62 | AC | 206 ms
46,976 KB |
testcase_63 | AC | 156 ms
44,436 KB |
testcase_64 | RE | - |
testcase_65 | AC | 133 ms
42,288 KB |
testcase_66 | RE | - |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.PriorityQueue; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int s = Integer.parseInt(sa[1]) - 1; int t = Integer.parseInt(sa[2]) - 1; int k = Integer.parseInt(sa[3]); sa = br.readLine().split(" "); int[] x = new int[n]; for (int i = 0; i < n; i++) { x[i] = Integer.parseInt(sa[i]); } List<List<Hen>> list = new ArrayList<>(n); for (int i = 0; i < n; i++) { list.add(new ArrayList<>()); } int m = Integer.parseInt(br.readLine()); for (int i = 0; i < m; i++) { sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]) - 1; int b = Integer.parseInt(sa[1]) - 1; int c = Integer.parseInt(sa[2]); list.get(a).add(new Hen(b, c)); } br.close(); if (n > 1000) { throw new Exception(); } int nk = n + k + 5; long[][] d = new long[n][nk]; int[][] pre = new int[n][nk]; for (int i = 0; i < n; i++) { Arrays.fill(d[i], Long.MAX_VALUE); } d[s][0] = x[s]; PriorityQueue<Node> que = new PriorityQueue<Node>(); Node first = new Node(s, 0, x[s]); que.add(first); while (!que.isEmpty()) { Node cur = que.poll(); if (cur.d > d[cur.v][cur.v2]) { continue; } for (Hen hen : list.get(cur.v)) { long alt = d[cur.v][cur.v2] + hen.c + x[hen.v]; int nx2 = cur.v2 + 1; if (nx2 < nk && alt < d[hen.v][nx2]) { d[hen.v][nx2] = alt; pre[hen.v][nx2] = cur.v; que.add(new Node(hen.v, nx2, alt)); } } } long ans = Long.MAX_VALUE; int ak = 0; for (int i = k - 1; i < d[t].length; i++) { if (d[t][i] < ans) { ans = d[t][i]; ak = i; } } if (ans == Long.MAX_VALUE) { System.out.println("Impossible"); return; } System.out.println("Possible"); System.out.println(ans); List<Integer> his = new ArrayList<>(); int now = t; his.add(now + 1); for (int i = ak; i > 0; i--) { now = pre[now][i]; his.add(now + 1); } System.out.println(his.size()); StringBuilder sb = new StringBuilder(); for (int i = his.size() - 1; i >= 0; i--) { sb.append(his.get(i)).append(' '); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); } static class Hen { int v, c; public Hen(int v, int c) { this.v = v; this.c = c; } } static class Node implements Comparable<Node> { int v, v2; long d; public Node(int v, int v2, long d) { this.v = v; this.v2 = v2; this.d = d; } public int compareTo(Node o) { return Long.compare(d, o.d); } } }