結果

問題 No.135 とりあえず1次元の問題
コンテスト
ユーザー kitamoto0407
提出日時 2025-11-29 20:06:30
言語 Java
(openjdk 23)
結果
AC  
実行時間 524 ms / 5,000 ms
コード長 1,168 bytes
記録
コンパイル時間 8,681 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 60,628 KB
最終ジャッジ日時 2025-11-29 20:06:49
合計ジャッジ時間 9,855 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.*;
import java.util.*;
import java.util.stream.*;

// 処理
class Process {
    private int[] X;

    Process(int[] X) {
        this.X = X;
    }

    int getResult() {
        int[] newX = IntStream.of(X).distinct().sorted().toArray();
        
        if(newX.length == 1) {
            return 0;
        }

        int minDistance = (newX[1] - newX[0]);
        for(int i = 1; i < (newX.length - 1); i++) {
            minDistance = Math.min(minDistance, (newX[i + 1] - newX[i]));
        }
        return minDistance;
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        var bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        var printWriter    = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        // 入力
        int N = Integer.parseInt(bufferedReader.readLine().trim());

        int[] X = Stream.of(bufferedReader.readLine().trim().split("[ ]+")).mapToInt(Integer::parseInt).toArray();

        // 出力
        printWriter.println((new Process(X)).getResult());

        bufferedReader.close();
        printWriter.close();
    }
}
0