結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | tenten |
提出日時 | 2023-07-24 16:46:16 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 2,150 ms / 3,000 ms |
コード長 | 3,124 bytes |
コンパイル時間 | 3,116 ms |
コンパイル使用メモリ | 96,480 KB |
実行使用メモリ | 182,548 KB |
最終ジャッジ日時 | 2024-10-01 11:42:08 |
合計ジャッジ時間 | 37,399 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
37,664 KB |
testcase_01 | AC | 62 ms
37,732 KB |
testcase_02 | AC | 60 ms
37,936 KB |
testcase_03 | AC | 2,118 ms
163,744 KB |
testcase_04 | AC | 1,983 ms
167,720 KB |
testcase_05 | AC | 62 ms
48,960 KB |
testcase_06 | AC | 1,115 ms
128,012 KB |
testcase_07 | AC | 1,426 ms
141,740 KB |
testcase_08 | AC | 1,897 ms
147,912 KB |
testcase_09 | AC | 2,057 ms
158,444 KB |
testcase_10 | AC | 1,574 ms
115,224 KB |
testcase_11 | AC | 1,523 ms
122,148 KB |
testcase_12 | AC | 1,668 ms
122,852 KB |
testcase_13 | AC | 1,337 ms
119,160 KB |
testcase_14 | AC | 1,504 ms
128,632 KB |
testcase_15 | AC | 2,150 ms
182,548 KB |
testcase_16 | AC | 1,590 ms
126,996 KB |
testcase_17 | AC | 72 ms
50,796 KB |
testcase_18 | AC | 1,708 ms
154,188 KB |
testcase_19 | AC | 2,007 ms
161,740 KB |
testcase_20 | AC | 1,206 ms
121,212 KB |
testcase_21 | AC | 1,546 ms
135,844 KB |
testcase_22 | AC | 1,455 ms
132,440 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] points = new int[n]; for (int i = 0; i < n; i++) { points[i] = sc.nextInt(); } HashMap<Integer, ArrayList<Integer>> relays = new HashMap<>(); PriorityQueue<Path> queue = new PriorityQueue<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (!relays.containsKey(points[i] - x)) { relays.put(points[i] - x, new ArrayList<>()); } relays.get(points[i] - x).add(i); if (!relays.containsKey(points[i] + x)) { relays.put(points[i] + x, new ArrayList<>()); } relays.get(points[i] + x).add(i); queue.add(new Path(i, points[i] + x)); } int[] ans = new int[n]; while (queue.size() > 0) { Path p = queue.poll(); if (ans[p.idx] > 0) { continue; } ans[p.idx] = p.value - points[p.idx]; if (relays.containsKey(points[p.idx])) { for (int x : relays.get(points[p.idx])) { if (ans[x] == 0) { queue.add(new Path(x, p.value)); } } } } System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } 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 Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }