結果

問題 No.135 とりあえず1次元の問題
ユーザー dazydazy
提出日時 2016-09-14 04:16:12
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,569 bytes
コンパイル時間 4,146 ms
コンパイル使用メモリ 73,912 KB
実行使用メモリ 73,316 KB
最終ジャッジ日時 2023-09-02 00:32:43
合計ジャッジ時間 15,818 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
evil01.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Run {
    public static void main (String arg[]) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] X = new int[N];
        for (int i = 0; i < N; i++) {
            X[i] = scan.nextInt();
        }
        heapSort(N, X);
        int min = X[1] - X[0];
        int tmp;
        for (int i = 1; i < N-1; i++) {
            tmp = X[i+1] - X[i];
            if ((min==0 && tmp!=0) || min > tmp) min = tmp;
        }
        System.out.println(min);
    }

    public static void heapSort (int leaf, int[] A) {
        int l = leaf;
        int tmp;
        for (int j = 0; j < l; j++) {
            int root = leaf/2-1;
            for (int i = root; i >= 0; i--) {
                while ((root + 1) * 2 <= leaf) {
                    if ((root + 1) * 2 == leaf) {
                        tmp = (root + 1) * 2 - 1;
                    } else {
                        if (A[(root + 1) * 2 - 1] < A[(root + 1) * 2]) tmp = (root + 1) * 2;
                        else tmp = (root + 1) * 2 - 1;
                    }
                    if (A[root] < A[tmp]) {
                        swap(A, root, tmp);
                        root = tmp;
                    } else break;
                }
                root = i - 1;
            }
            tmp = A[0];
            A[0] = A[leaf-1];
            A[leaf-1] = tmp;
            leaf--;
        }
    }

    public static void swap (int[] A, int a, int b){
        int tmp;
        tmp = A[a];
        A[a] = A[b];
        A[b] = tmp;
    }
}
0