結果

問題 No.2248 max(C)-min(C)
ユーザー tentententen
提出日時 2023-03-20 18:45:58
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,448 bytes
コンパイル時間 4,329 ms
コンパイル使用メモリ 85,912 KB
実行使用メモリ 148,508 KB
最終ジャッジ日時 2023-11-27 11:43:21
合計ジャッジ時間 66,537 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
54,224 KB
testcase_01 AC 63 ms
54,216 KB
testcase_02 AC 60 ms
54,236 KB
testcase_03 AC 122 ms
57,096 KB
testcase_04 AC 113 ms
56,212 KB
testcase_05 AC 86 ms
55,520 KB
testcase_06 AC 135 ms
57,084 KB
testcase_07 AC 141 ms
56,900 KB
testcase_08 AC 144 ms
56,840 KB
testcase_09 AC 137 ms
56,836 KB
testcase_10 AC 91 ms
55,680 KB
testcase_11 AC 142 ms
57,064 KB
testcase_12 AC 114 ms
56,844 KB
testcase_13 AC 134 ms
57,560 KB
testcase_14 AC 140 ms
56,480 KB
testcase_15 AC 142 ms
57,072 KB
testcase_16 AC 124 ms
56,624 KB
testcase_17 AC 143 ms
57,160 KB
testcase_18 AC 2,172 ms
110,296 KB
testcase_19 AC 484 ms
65,976 KB
testcase_20 AC 2,279 ms
118,360 KB
testcase_21 AC 2,223 ms
120,880 KB
testcase_22 AC 1,419 ms
94,136 KB
testcase_23 AC 1,015 ms
80,468 KB
testcase_24 AC 596 ms
69,476 KB
testcase_25 AC 2,149 ms
109,132 KB
testcase_26 AC 1,879 ms
121,820 KB
testcase_27 AC 2,071 ms
107,708 KB
testcase_28 AC 397 ms
64,688 KB
testcase_29 AC 1,746 ms
121,912 KB
testcase_30 AC 1,001 ms
80,588 KB
testcase_31 AC 2,538 ms
117,188 KB
testcase_32 AC 621 ms
69,364 KB
testcase_33 AC 807 ms
78,248 KB
testcase_34 AC 2,207 ms
115,604 KB
testcase_35 AC 2,262 ms
118,384 KB
testcase_36 AC 2,528 ms
114,220 KB
testcase_37 AC 1,251 ms
85,068 KB
testcase_38 AC 2,914 ms
127,204 KB
testcase_39 TLE -
testcase_40 AC 2,989 ms
123,156 KB
testcase_41 AC 2,198 ms
121,188 KB
testcase_42 AC 2,705 ms
121,192 KB
testcase_43 AC 2,515 ms
121,064 KB
testcase_44 TLE -
testcase_45 AC 2,320 ms
118,360 KB
testcase_46 AC 1,400 ms
85,316 KB
testcase_47 TLE -
testcase_48 AC 1,279 ms
105,832 KB
testcase_49 TLE -
testcase_50 TLE -
testcase_51 TLE -
testcase_52 TLE -
testcase_53 AC 844 ms
70,284 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[] valuesA = new int[n];
        for (int i = 0; i < n; i++) {
            valuesA[i] = sc.nextInt();
        }
        TreeSet<Integer> mins = new TreeSet<>();
        TreeSet<Unit> units = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            mins.add(x);
            mins.add(valuesA[i]);
            mins.add((x + valuesA[i]) / 2);
            units.add(new Unit(i, x, valuesA[i]));
        }
        int ans = Integer.MAX_VALUE;
        boolean cont = true;
        for (int x : mins) {
            while (units.first().getValue() < x) {
                Unit y = units.pollFirst();
                if (!y.add()) {
                    cont = false;
                    break;
                }
                units.add(y);
            }
            if (!cont) {
                break;
            }
            ans = Math.min(ans, units.last().getValue() - x);
        }
        System.out.println(ans);
    }
    
    static class Unit implements Comparable<Unit> {
        int current;
        int idx;
        int[] values;
        
        public Unit(int idx, int a, int b) {
            this.idx = idx;
            values = new int[]{a, b, (a + b) / 2};
            Arrays.sort(values);
        }
        
        public int hashCode() {
            return idx;
        }
        
        public boolean equals(Object o) {
            Unit x = (Unit)o;
            return idx == x.idx;
        }
        
        public int compareTo(Unit another) {
            if (getValue() == another.getValue()) {
                return idx - another.idx;
            } else {
                return getValue() - another.getValue();
            }
        }
        
        public int getValue() {
            return values[current];
        }
        
        public boolean add() {
            if (current == 2) {
                return false;
            } else {
                current++;
                return true;
            }
        }
    }
}
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