結果
問題 | No.1898 Battle and Exchange |
ユーザー | Shirotsume |
提出日時 | 2022-03-28 03:18:04 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 2,860 ms / 5,000 ms |
コード長 | 3,132 bytes |
コンパイル時間 | 2,726 ms |
コンパイル使用メモリ | 81,260 KB |
実行使用メモリ | 96,588 KB |
最終ジャッジ日時 | 2024-11-06 19:49:17 |
合計ジャッジ時間 | 67,294 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 143 ms
54,280 KB |
testcase_01 | AC | 139 ms
54,192 KB |
testcase_02 | AC | 143 ms
54,264 KB |
testcase_03 | AC | 142 ms
54,088 KB |
testcase_04 | AC | 213 ms
56,764 KB |
testcase_05 | AC | 212 ms
56,572 KB |
testcase_06 | AC | 233 ms
57,000 KB |
testcase_07 | AC | 228 ms
56,876 KB |
testcase_08 | AC | 207 ms
54,556 KB |
testcase_09 | AC | 547 ms
59,824 KB |
testcase_10 | AC | 145 ms
54,256 KB |
testcase_11 | AC | 165 ms
54,780 KB |
testcase_12 | AC | 256 ms
57,812 KB |
testcase_13 | AC | 144 ms
54,292 KB |
testcase_14 | AC | 230 ms
57,516 KB |
testcase_15 | AC | 148 ms
54,084 KB |
testcase_16 | AC | 227 ms
56,812 KB |
testcase_17 | AC | 473 ms
59,512 KB |
testcase_18 | AC | 931 ms
71,512 KB |
testcase_19 | AC | 1,299 ms
73,908 KB |
testcase_20 | AC | 1,158 ms
73,828 KB |
testcase_21 | AC | 2,311 ms
85,732 KB |
testcase_22 | AC | 170 ms
54,312 KB |
testcase_23 | AC | 218 ms
56,708 KB |
testcase_24 | AC | 220 ms
56,632 KB |
testcase_25 | AC | 234 ms
56,936 KB |
testcase_26 | AC | 154 ms
54,008 KB |
testcase_27 | AC | 320 ms
58,916 KB |
testcase_28 | AC | 380 ms
59,232 KB |
testcase_29 | AC | 564 ms
59,460 KB |
testcase_30 | AC | 261 ms
58,352 KB |
testcase_31 | AC | 209 ms
54,616 KB |
testcase_32 | AC | 1,156 ms
73,800 KB |
testcase_33 | AC | 1,526 ms
75,316 KB |
testcase_34 | AC | 951 ms
73,624 KB |
testcase_35 | AC | 1,317 ms
75,404 KB |
testcase_36 | AC | 1,147 ms
73,340 KB |
testcase_37 | AC | 704 ms
59,916 KB |
testcase_38 | AC | 2,449 ms
86,388 KB |
testcase_39 | AC | 1,594 ms
86,744 KB |
testcase_40 | AC | 2,587 ms
86,628 KB |
testcase_41 | AC | 1,531 ms
86,684 KB |
testcase_42 | AC | 432 ms
59,428 KB |
testcase_43 | AC | 1,584 ms
79,720 KB |
testcase_44 | AC | 176 ms
54,356 KB |
testcase_45 | AC | 622 ms
59,288 KB |
testcase_46 | AC | 1,318 ms
73,420 KB |
testcase_47 | AC | 519 ms
59,488 KB |
testcase_48 | AC | 659 ms
59,836 KB |
testcase_49 | AC | 337 ms
58,964 KB |
testcase_50 | AC | 347 ms
59,280 KB |
testcase_51 | AC | 325 ms
58,700 KB |
testcase_52 | AC | 468 ms
59,172 KB |
testcase_53 | AC | 914 ms
70,048 KB |
testcase_54 | AC | 1,133 ms
73,432 KB |
testcase_55 | AC | 1,200 ms
73,484 KB |
testcase_56 | AC | 1,097 ms
72,628 KB |
testcase_57 | AC | 2,860 ms
86,652 KB |
testcase_58 | AC | 2,793 ms
96,588 KB |
testcase_59 | AC | 2,654 ms
96,344 KB |
testcase_60 | AC | 2,486 ms
85,968 KB |
ソースコード
import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void upd(int A, int B, int C, int x){ if (C < x){ A = B; B = C; C = x; } else if (B < x){ A = B; B = x; } else if(A < x){ A = x; } return; } public static boolean solve(int n, int m, int minv, int[] a, int[] b, int[] c, int[] d, ArrayList<Integer>[] graph, int nowc){ int A = 1; int B = 1; int C = nowc; if(d[0] >= A + B + C) return false; int x = c[0]; if (C < x){ A = B; B = C; C = x; } else if (B < x){ A = B; B = x; } else if(A < x){ A = x; } if (d[minv] >= A + B + C) return false; A = 1; B = 1; PriorityQueue<Pair> Q = new PriorityQueue<>(); Q.add(new Pair(d[0], 0)); boolean[] visit = new boolean[n]; for(int i = 0; i < n; i++){ visit[i] = false; } visit[0] = true; int sum, now; while(Q.size() > 0){ Pair temp = Q.poll(); sum = temp.time; now = temp.ver; if(sum >= A + B + C) return false; if(now == n - 1) return true; x = a[now]; if (C < x){ A = B; B = C; C = x; } else if (B < x){ A = B; B = x; } else if(A < x){ A = x; } x = b[now]; if (C < x){ A = B; B = C; C = x; } else if (B < x){ A = B; B = x; } else if(A < x){ A = x; } x = c[now]; if (C < x){ A = B; B = C; C = x; } else if (B < x){ A = B; B = x; } else if(A < x){ A = x; } for(int to: graph[now]){ if (!visit[to]){ visit[to] = true; Q.add(new Pair(d[to], to)); } } } return false; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, m; n = sc.nextInt(); m = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[n]; ArrayList<Integer>[] graph = new ArrayList[n]; for(int i = 0; i < n; i++){ graph[i] = new ArrayList<Integer>(); } int u, v; for(int i = 0; i < m ;i++){ u = sc.nextInt(); v = sc.nextInt(); u--; v--; graph[u].add(v); graph[v].add(u); } for(int i = 0; i < n; i++){ a[i] = sc.nextInt(); b[i] = sc.nextInt(); c[i] = sc.nextInt(); } int[] d = new int[n]; for(int i = 0; i < n; i++){ d[i] = a[i] + b[i] + c[i]; } int min , max; for(int i = 0; i < n; i++){ min = Math.min(Math.min(a[i], b[i]), c[i]); max = Math.max(Math.max(a[i], b[i]), c[i]); a[i] = min; b[i] = d[i] - min - max; c[i] = max; } int mint = graph[0].get(0); for(int to: graph[0]){ if(d[to] < d[mint]) mint = to; } int ok = 1000000000; int ng = 1; int mid; while(Math.abs(ok - ng) > 1){ mid = (ok + ng) / 2; if(solve(n, m, mint, a, b, c, d, graph, mid)){ ok = mid; } else ng = mid; } System.out.printf("%d %d %d\n", ok, 1, 1); } } class Pair implements Comparable<Pair>{ int time; int ver; public Pair(int time, int ver) { this.time = time; this.ver = ver; } @Override public int compareTo(Pair p) { return Integer.compare(time, p.time); } }