結果

問題 No.135 とりあえず1次元の問題
ユーザー dazy
提出日時 2016-09-14 04:16:12
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 1,569 bytes
コンパイル時間 3,513 ms
コンパイル使用メモリ 76,724 KB
実行使用メモリ 75,856 KB
最終ジャッジ日時 2024-06-11 06:57:47
合計ジャッジ時間 15,572 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

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