結果
問題 | No.2248 max(C)-min(C) |
ユーザー | tenten |
提出日時 | 2023-03-30 16:26:36 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,558 ms / 3,000 ms |
コード長 | 2,930 bytes |
コンパイル時間 | 3,146 ms |
コンパイル使用メモリ | 84,732 KB |
実行使用メモリ | 96,536 KB |
最終ジャッジ日時 | 2024-09-22 04:01:04 |
合計ジャッジ時間 | 38,590 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
50,316 KB |
testcase_01 | AC | 53 ms
50,500 KB |
testcase_02 | AC | 52 ms
50,312 KB |
testcase_03 | AC | 81 ms
51,628 KB |
testcase_04 | AC | 75 ms
51,548 KB |
testcase_05 | AC | 76 ms
51,312 KB |
testcase_06 | AC | 112 ms
53,040 KB |
testcase_07 | AC | 112 ms
52,592 KB |
testcase_08 | AC | 115 ms
52,712 KB |
testcase_09 | AC | 110 ms
52,556 KB |
testcase_10 | AC | 64 ms
50,620 KB |
testcase_11 | AC | 105 ms
52,984 KB |
testcase_12 | AC | 93 ms
51,360 KB |
testcase_13 | AC | 108 ms
52,796 KB |
testcase_14 | AC | 102 ms
52,900 KB |
testcase_15 | AC | 113 ms
52,928 KB |
testcase_16 | AC | 83 ms
51,376 KB |
testcase_17 | AC | 112 ms
52,936 KB |
testcase_18 | AC | 741 ms
77,604 KB |
testcase_19 | AC | 243 ms
57,520 KB |
testcase_20 | AC | 868 ms
86,180 KB |
testcase_21 | AC | 776 ms
77,372 KB |
testcase_22 | AC | 598 ms
73,708 KB |
testcase_23 | AC | 466 ms
65,540 KB |
testcase_24 | AC | 275 ms
58,588 KB |
testcase_25 | AC | 759 ms
81,236 KB |
testcase_26 | AC | 690 ms
72,580 KB |
testcase_27 | AC | 710 ms
82,864 KB |
testcase_28 | AC | 204 ms
55,820 KB |
testcase_29 | AC | 770 ms
73,272 KB |
testcase_30 | AC | 405 ms
62,004 KB |
testcase_31 | AC | 985 ms
90,296 KB |
testcase_32 | AC | 291 ms
58,796 KB |
testcase_33 | AC | 388 ms
62,180 KB |
testcase_34 | AC | 861 ms
86,480 KB |
testcase_35 | AC | 967 ms
90,160 KB |
testcase_36 | AC | 967 ms
89,940 KB |
testcase_37 | AC | 560 ms
67,592 KB |
testcase_38 | AC | 1,021 ms
91,196 KB |
testcase_39 | AC | 1,086 ms
91,212 KB |
testcase_40 | AC | 1,109 ms
91,804 KB |
testcase_41 | AC | 968 ms
84,924 KB |
testcase_42 | AC | 1,210 ms
92,080 KB |
testcase_43 | AC | 909 ms
80,732 KB |
testcase_44 | AC | 1,274 ms
96,536 KB |
testcase_45 | AC | 925 ms
77,980 KB |
testcase_46 | AC | 619 ms
65,972 KB |
testcase_47 | AC | 1,008 ms
90,700 KB |
testcase_48 | AC | 905 ms
93,292 KB |
testcase_49 | AC | 1,558 ms
96,440 KB |
testcase_50 | AC | 1,361 ms
90,356 KB |
testcase_51 | AC | 1,336 ms
90,648 KB |
testcase_52 | AC | 1,466 ms
91,188 KB |
testcase_53 | AC | 432 ms
62,456 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<Unit> units = new TreeSet<>(); for (int i = 0; i < n; i++) { units.add(new Unit(i, values[i], sc.nextInt())); } int ans = Integer.MAX_VALUE; while (true) { Unit x = units.pollFirst(); ans = Math.min(ans, units.last().value() - x.value()); if (!x.add()) { break; } units.add(x); } System.out.println(ans); } static class Unit implements Comparable<Unit> { int[] values; int idx; int current; public Unit(int idx, int a, int b) { this.idx = idx; values = new int[]{a, b, (a + b) / 2}; Arrays.sort(values); } public int value() { return values[current]; } public int compareTo(Unit 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 boolean add() { current++; return current < 3; } } } 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(); } }