結果

問題 No.2248 max(C)-min(C)
ユーザー tentententen
提出日時 2023-03-30 16:26:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,425 ms / 3,000 ms
コード長 2,930 bytes
コンパイル時間 4,496 ms
コンパイル使用メモリ 84,704 KB
実行使用メモリ 95,020 KB
最終ジャッジ日時 2023-10-22 02:23:16
合計ジャッジ時間 38,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
36,932 KB
testcase_01 AC 50 ms
36,996 KB
testcase_02 AC 49 ms
36,932 KB
testcase_03 AC 85 ms
38,128 KB
testcase_04 AC 78 ms
38,116 KB
testcase_05 AC 58 ms
37,296 KB
testcase_06 AC 102 ms
40,196 KB
testcase_07 AC 107 ms
39,908 KB
testcase_08 AC 105 ms
40,016 KB
testcase_09 AC 96 ms
39,248 KB
testcase_10 AC 73 ms
37,240 KB
testcase_11 AC 107 ms
39,892 KB
testcase_12 AC 85 ms
38,156 KB
testcase_13 AC 100 ms
39,596 KB
testcase_14 AC 99 ms
39,884 KB
testcase_15 AC 107 ms
39,672 KB
testcase_16 AC 76 ms
38,256 KB
testcase_17 AC 94 ms
39,512 KB
testcase_18 AC 659 ms
66,812 KB
testcase_19 AC 220 ms
56,692 KB
testcase_20 AC 879 ms
74,880 KB
testcase_21 AC 736 ms
80,660 KB
testcase_22 AC 610 ms
61,412 KB
testcase_23 AC 439 ms
55,352 KB
testcase_24 AC 259 ms
47,048 KB
testcase_25 AC 723 ms
74,452 KB
testcase_26 AC 600 ms
74,584 KB
testcase_27 AC 838 ms
70,960 KB
testcase_28 AC 207 ms
57,092 KB
testcase_29 AC 600 ms
63,284 KB
testcase_30 AC 376 ms
62,852 KB
testcase_31 AC 890 ms
78,784 KB
testcase_32 AC 265 ms
58,620 KB
testcase_33 AC 318 ms
65,280 KB
testcase_34 AC 736 ms
74,828 KB
testcase_35 AC 881 ms
84,724 KB
testcase_36 AC 790 ms
90,288 KB
testcase_37 AC 485 ms
70,272 KB
testcase_38 AC 1,033 ms
86,272 KB
testcase_39 AC 1,051 ms
95,020 KB
testcase_40 AC 1,171 ms
92,872 KB
testcase_41 AC 875 ms
81,428 KB
testcase_42 AC 1,162 ms
89,252 KB
testcase_43 AC 860 ms
80,304 KB
testcase_44 AC 1,012 ms
88,060 KB
testcase_45 AC 826 ms
77,364 KB
testcase_46 AC 567 ms
67,432 KB
testcase_47 AC 1,166 ms
84,988 KB
testcase_48 AC 870 ms
92,404 KB
testcase_49 AC 1,425 ms
91,160 KB
testcase_50 AC 1,388 ms
94,268 KB
testcase_51 AC 1,358 ms
91,928 KB
testcase_52 AC 1,283 ms
89,488 KB
testcase_53 AC 391 ms
63,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0