結果
問題 | No.2248 max(C)-min(C) |
ユーザー | tenten |
提出日時 | 2023-07-26 16:55:00 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,221 ms / 3,000 ms |
コード長 | 3,179 bytes |
コンパイル時間 | 9,226 ms |
コンパイル使用メモリ | 91,632 KB |
実行使用メモリ | 86,188 KB |
最終ジャッジ日時 | 2024-10-03 03:48:39 |
合計ジャッジ時間 | 38,029 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
37,216 KB |
testcase_01 | AC | 47 ms
37,316 KB |
testcase_02 | AC | 46 ms
36,940 KB |
testcase_03 | AC | 77 ms
38,644 KB |
testcase_04 | AC | 65 ms
38,576 KB |
testcase_05 | AC | 60 ms
37,348 KB |
testcase_06 | AC | 106 ms
40,436 KB |
testcase_07 | AC | 97 ms
40,464 KB |
testcase_08 | AC | 107 ms
40,416 KB |
testcase_09 | AC | 89 ms
40,484 KB |
testcase_10 | AC | 56 ms
37,584 KB |
testcase_11 | AC | 101 ms
40,252 KB |
testcase_12 | AC | 74 ms
38,692 KB |
testcase_13 | AC | 99 ms
39,908 KB |
testcase_14 | AC | 103 ms
40,120 KB |
testcase_15 | AC | 100 ms
40,312 KB |
testcase_16 | AC | 81 ms
38,508 KB |
testcase_17 | AC | 89 ms
40,424 KB |
testcase_18 | AC | 695 ms
67,060 KB |
testcase_19 | AC | 194 ms
45,620 KB |
testcase_20 | AC | 726 ms
77,736 KB |
testcase_21 | AC | 702 ms
66,100 KB |
testcase_22 | AC | 528 ms
61,700 KB |
testcase_23 | AC | 405 ms
57,056 KB |
testcase_24 | AC | 236 ms
47,432 KB |
testcase_25 | AC | 632 ms
69,984 KB |
testcase_26 | AC | 607 ms
62,776 KB |
testcase_27 | AC | 648 ms
69,816 KB |
testcase_28 | AC | 196 ms
45,048 KB |
testcase_29 | AC | 555 ms
62,508 KB |
testcase_30 | AC | 352 ms
52,072 KB |
testcase_31 | AC | 765 ms
77,948 KB |
testcase_32 | AC | 251 ms
47,364 KB |
testcase_33 | AC | 324 ms
52,192 KB |
testcase_34 | AC | 779 ms
66,112 KB |
testcase_35 | AC | 805 ms
78,228 KB |
testcase_36 | AC | 767 ms
77,864 KB |
testcase_37 | AC | 449 ms
58,080 KB |
testcase_38 | AC | 995 ms
79,968 KB |
testcase_39 | AC | 1,021 ms
83,204 KB |
testcase_40 | AC | 974 ms
78,448 KB |
testcase_41 | AC | 761 ms
73,376 KB |
testcase_42 | AC | 884 ms
78,644 KB |
testcase_43 | AC | 775 ms
76,852 KB |
testcase_44 | AC | 989 ms
83,172 KB |
testcase_45 | AC | 685 ms
68,452 KB |
testcase_46 | AC | 513 ms
56,360 KB |
testcase_47 | AC | 867 ms
83,168 KB |
testcase_48 | AC | 799 ms
86,188 KB |
testcase_49 | AC | 1,221 ms
81,572 KB |
testcase_50 | AC | 1,079 ms
84,756 KB |
testcase_51 | AC | 1,111 ms
80,616 KB |
testcase_52 | AC | 1,072 ms
84,560 KB |
testcase_53 | AC | 372 ms
51,056 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[] tmp = new int[n]; for (int i = 0; i < n; i++) { tmp[i] = sc.nextInt(); } TreeSet<Num> all = new TreeSet<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); all.add(new Num(i, x, tmp[i], (x + tmp[i]) / 2)); } int ans = Integer.MAX_VALUE; while (true) { ans = Math.min(ans, all.last().value() - all.first().value()); Num x = all.pollFirst(); x.add(); if (!x.enable()) { break; } all.add(x); } System.out.println(ans); } static class Num implements Comparable<Num> { int idx; int[] values; int current; public Num(int idx, int a, int b, int c) { this.idx = idx; values = new int[]{a, b, c}; Arrays.sort(values); current = 0; } public int value() { return values[current]; } public void add() { current++; } public boolean enable() { return current < values.length; } public int compareTo(Num another) { if (value() == another.value()) { return idx - another.idx; } else { return value() - another.value(); } } public boolean equals(Object o) { return hashCode() == o.hashCode(); } public String toString() { return String.valueOf(value()); } public int hashCode() { return idx; } } } 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(); } }