結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | tenten |
提出日時 | 2022-05-26 09:02:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,754 ms / 3,000 ms |
コード長 | 2,703 bytes |
コンパイル時間 | 5,145 ms |
コンパイル使用メモリ | 79,508 KB |
実行使用メモリ | 129,424 KB |
最終ジャッジ日時 | 2023-10-20 19:21:57 |
合計ジャッジ時間 | 30,998 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
53,632 KB |
testcase_01 | AC | 57 ms
53,640 KB |
testcase_02 | AC | 55 ms
53,636 KB |
testcase_03 | AC | 1,295 ms
118,072 KB |
testcase_04 | AC | 1,240 ms
118,372 KB |
testcase_05 | AC | 56 ms
53,576 KB |
testcase_06 | AC | 1,207 ms
129,424 KB |
testcase_07 | AC | 1,024 ms
101,344 KB |
testcase_08 | AC | 1,114 ms
102,768 KB |
testcase_09 | AC | 1,287 ms
118,008 KB |
testcase_10 | AC | 1,210 ms
110,612 KB |
testcase_11 | AC | 1,164 ms
111,172 KB |
testcase_12 | AC | 1,235 ms
111,220 KB |
testcase_13 | AC | 1,274 ms
117,916 KB |
testcase_14 | AC | 1,293 ms
122,124 KB |
testcase_15 | AC | 1,754 ms
109,644 KB |
testcase_16 | AC | 1,302 ms
128,552 KB |
testcase_17 | AC | 56 ms
53,632 KB |
testcase_18 | AC | 1,151 ms
107,208 KB |
testcase_19 | AC | 1,652 ms
111,400 KB |
testcase_20 | AC | 1,008 ms
102,532 KB |
testcase_21 | AC | 1,290 ms
118,528 KB |
testcase_22 | AC | 1,362 ms
118,484 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] positions = new int[n]; TreeMap<Integer, Integer> map = new TreeMap<>(); ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { positions[i] = sc.nextInt(); map.put(positions[i], i); graph.add(new ArrayList<>()); } int[] distances = new int[n]; for (int i = 0; i < n; i++) { distances[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { if (map.containsKey(positions[i] + distances[i])) { graph.get(map.get(positions[i] + distances[i])).add(i); } if (map.containsKey(positions[i] - distances[i])) { graph.get(map.get(positions[i] - distances[i])).add(i); } } PriorityQueue<Path> queue = new PriorityQueue<>(); int[] ans = new int[n]; for (int i = 0; i < n; i++) { queue.add(new Path(i, positions[i] + distances[i])); } while (queue.size() > 0) { Path p = queue.poll(); if (ans[p.idx] >= p.value) { continue; } ans[p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value)); } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(ans[i] - positions[i]).append("\n"); } System.out.print(sb); } static class Path implements Comparable<Path> { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return another.value - value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }