結果
問題 | No.2248 max(C)-min(C) |
ユーザー | tenten |
提出日時 | 2023-04-27 15:28:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,656 ms / 3,000 ms |
コード長 | 3,146 bytes |
コンパイル時間 | 2,943 ms |
コンパイル使用メモリ | 96,228 KB |
実行使用メモリ | 99,456 KB |
最終ジャッジ日時 | 2023-11-09 23:54:37 |
合計ジャッジ時間 | 42,661 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
54,124 KB |
testcase_01 | AC | 54 ms
53,996 KB |
testcase_02 | AC | 54 ms
54,000 KB |
testcase_03 | AC | 92 ms
55,024 KB |
testcase_04 | AC | 89 ms
55,280 KB |
testcase_05 | AC | 81 ms
54,872 KB |
testcase_06 | AC | 115 ms
56,820 KB |
testcase_07 | AC | 105 ms
56,684 KB |
testcase_08 | AC | 106 ms
56,684 KB |
testcase_09 | AC | 117 ms
56,412 KB |
testcase_10 | AC | 78 ms
54,628 KB |
testcase_11 | AC | 117 ms
56,716 KB |
testcase_12 | AC | 97 ms
55,536 KB |
testcase_13 | AC | 109 ms
55,916 KB |
testcase_14 | AC | 108 ms
56,176 KB |
testcase_15 | AC | 111 ms
56,688 KB |
testcase_16 | AC | 98 ms
55,300 KB |
testcase_17 | AC | 118 ms
56,552 KB |
testcase_18 | AC | 692 ms
80,568 KB |
testcase_19 | AC | 231 ms
60,092 KB |
testcase_20 | AC | 923 ms
90,576 KB |
testcase_21 | AC | 876 ms
82,136 KB |
testcase_22 | AC | 635 ms
75,668 KB |
testcase_23 | AC | 511 ms
69,232 KB |
testcase_24 | AC | 297 ms
62,376 KB |
testcase_25 | AC | 864 ms
86,256 KB |
testcase_26 | AC | 705 ms
76,860 KB |
testcase_27 | AC | 809 ms
85,112 KB |
testcase_28 | AC | 213 ms
59,664 KB |
testcase_29 | AC | 713 ms
75,720 KB |
testcase_30 | AC | 454 ms
66,060 KB |
testcase_31 | AC | 986 ms
92,972 KB |
testcase_32 | AC | 302 ms
62,500 KB |
testcase_33 | AC | 395 ms
66,032 KB |
testcase_34 | AC | 987 ms
93,128 KB |
testcase_35 | AC | 988 ms
92,988 KB |
testcase_36 | AC | 920 ms
88,736 KB |
testcase_37 | AC | 606 ms
70,240 KB |
testcase_38 | AC | 1,353 ms
99,436 KB |
testcase_39 | AC | 1,350 ms
99,448 KB |
testcase_40 | AC | 1,372 ms
99,444 KB |
testcase_41 | AC | 1,005 ms
88,216 KB |
testcase_42 | AC | 1,344 ms
99,440 KB |
testcase_43 | AC | 1,061 ms
92,500 KB |
testcase_44 | AC | 1,336 ms
99,424 KB |
testcase_45 | AC | 985 ms
81,640 KB |
testcase_46 | AC | 688 ms
69,712 KB |
testcase_47 | AC | 1,412 ms
99,456 KB |
testcase_48 | AC | 892 ms
94,680 KB |
testcase_49 | AC | 1,656 ms
96,272 KB |
testcase_50 | AC | 1,634 ms
98,180 KB |
testcase_51 | AC | 1,614 ms
95,200 KB |
testcase_52 | AC | 1,540 ms
96,404 KB |
testcase_53 | AC | 438 ms
66,028 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(); } }