提出 #24662528


ソースコード 拡げる

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int(), M = in.Int();
            int[] A = in.Int(N);
            int[] B = in.Int(M);
            Arrays.sort(A);
            Arrays.sort(B);

            int min = Integer.MAX_VALUE;
            for (int a : A) {
                int idx = Arrays.binarySearch(B, a);
                if (idx < 0) idx ^= -1;
                if (M <= idx) idx = M - 1;
                min = Math.min(min, Math.abs(a - B[idx]));
                if (0 < idx)
                    min = Math.min(min, Math.abs(a - B[idx - 1]));
            }
            out.println(min);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}

提出情報

提出日時
問題 C - Min Difference
ユーザ daira4000
言語 Java (OpenJDK 11.0.6)
得点 300
コード長 2457 Byte
結果 AC
実行時間 450 ms
メモリ 62856 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 20
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, small_00.txt, small_01.txt, small_02.txt, small_03.txt, small_04.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 81 ms 32512 KiB
example_01.txt AC 67 ms 32440 KiB
example_02.txt AC 77 ms 32632 KiB
hand_00.txt AC 274 ms 55196 KiB
hand_01.txt AC 327 ms 59840 KiB
random_00.txt AC 409 ms 60380 KiB
random_01.txt AC 424 ms 61908 KiB
random_02.txt AC 421 ms 59516 KiB
random_03.txt AC 419 ms 62384 KiB
random_04.txt AC 436 ms 62856 KiB
random_05.txt AC 450 ms 62328 KiB
random_06.txt AC 449 ms 62392 KiB
random_07.txt AC 425 ms 62844 KiB
random_08.txt AC 413 ms 61016 KiB
random_09.txt AC 414 ms 60840 KiB
small_00.txt AC 123 ms 36056 KiB
small_01.txt AC 139 ms 36416 KiB
small_02.txt AC 118 ms 35648 KiB
small_03.txt AC 147 ms 36680 KiB
small_04.txt AC 85 ms 33564 KiB