結果
問題 | No.2248 max(C)-min(C) |
ユーザー | tenten |
提出日時 | 2023-04-27 15:28:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,726 ms / 3,000 ms |
コード長 | 3,146 bytes |
コンパイル時間 | 3,241 ms |
コンパイル使用メモリ | 85,452 KB |
実行使用メモリ | 84,588 KB |
最終ジャッジ日時 | 2024-09-26 00:39:13 |
合計ジャッジ時間 | 40,157 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
36,884 KB |
testcase_01 | AC | 50 ms
36,760 KB |
testcase_02 | AC | 48 ms
36,688 KB |
testcase_03 | AC | 84 ms
38,136 KB |
testcase_04 | AC | 78 ms
38,556 KB |
testcase_05 | AC | 67 ms
37,344 KB |
testcase_06 | AC | 103 ms
40,184 KB |
testcase_07 | AC | 112 ms
40,216 KB |
testcase_08 | AC | 108 ms
39,924 KB |
testcase_09 | AC | 107 ms
40,028 KB |
testcase_10 | AC | 61 ms
37,388 KB |
testcase_11 | AC | 108 ms
40,000 KB |
testcase_12 | AC | 84 ms
38,036 KB |
testcase_13 | AC | 106 ms
39,988 KB |
testcase_14 | AC | 110 ms
40,048 KB |
testcase_15 | AC | 109 ms
40,148 KB |
testcase_16 | AC | 74 ms
38,392 KB |
testcase_17 | AC | 106 ms
40,084 KB |
testcase_18 | AC | 720 ms
66,116 KB |
testcase_19 | AC | 219 ms
45,368 KB |
testcase_20 | AC | 805 ms
74,552 KB |
testcase_21 | AC | 728 ms
65,428 KB |
testcase_22 | AC | 569 ms
61,648 KB |
testcase_23 | AC | 452 ms
56,748 KB |
testcase_24 | AC | 269 ms
47,440 KB |
testcase_25 | AC | 806 ms
74,012 KB |
testcase_26 | AC | 602 ms
62,564 KB |
testcase_27 | AC | 710 ms
70,180 KB |
testcase_28 | AC | 196 ms
45,784 KB |
testcase_29 | AC | 672 ms
62,848 KB |
testcase_30 | AC | 383 ms
51,964 KB |
testcase_31 | AC | 862 ms
65,588 KB |
testcase_32 | AC | 281 ms
46,960 KB |
testcase_33 | AC | 332 ms
52,164 KB |
testcase_34 | AC | 861 ms
78,200 KB |
testcase_35 | AC | 964 ms
77,716 KB |
testcase_36 | AC | 968 ms
77,076 KB |
testcase_37 | AC | 667 ms
57,924 KB |
testcase_38 | AC | 993 ms
78,292 KB |
testcase_39 | AC | 1,132 ms
78,292 KB |
testcase_40 | AC | 1,216 ms
78,396 KB |
testcase_41 | AC | 911 ms
72,960 KB |
testcase_42 | AC | 1,217 ms
78,276 KB |
testcase_43 | AC | 981 ms
76,564 KB |
testcase_44 | AC | 1,234 ms
78,380 KB |
testcase_45 | AC | 856 ms
68,064 KB |
testcase_46 | AC | 578 ms
56,212 KB |
testcase_47 | AC | 1,103 ms
77,652 KB |
testcase_48 | AC | 964 ms
81,148 KB |
testcase_49 | AC | 1,516 ms
81,556 KB |
testcase_50 | AC | 1,682 ms
84,588 KB |
testcase_51 | AC | 1,726 ms
84,540 KB |
testcase_52 | AC | 1,401 ms
84,224 KB |
testcase_53 | AC | 384 ms
50,756 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[] values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); } TreeSet<Num> queue = new TreeSet<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); queue.add(new Num(i, values[i], x, (values[i] + x) / 2)); } int ans = Integer.MAX_VALUE; while (true) { Num x = queue.pollFirst(); ans = Math.min(ans, queue.last().value() - x.value()); if (!x.canAdd()) { break; } x.add(); queue.add(x); } System.out.println(ans); } static class Num implements Comparable<Num> { int idx; int[] values; int current = 0; public Num(int idx, int a, int b, int c) { this.idx = idx; values = new int[]{a, b, c}; Arrays.sort(values); } public boolean canAdd() { return current < 2; } public void add() { current++; } public int value() { return values[current]; } public int compareTo(Num another) { if (value() == another.value()) { return idx - another.idx; } else { return value() - another.value(); } } public int hashCode() { return idx; } public boolean equals(Object o) { return hashCode() == o.hashCode(); } public String toString() { return idx + Arrays.toString(values); } } } 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(); } }