結果

問題 No.135 とりあえず1次元の問題
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-06 22:27:13
言語 Java19
(openjdk 21)
結果
AC  
実行時間 594 ms / 5,000 ms
コード長 765 bytes
コンパイル時間 1,869 ms
コンパイル使用メモリ 71,988 KB
実行使用メモリ 61,080 KB
最終ジャッジ日時 2023-09-01 03:16:50
合計ジャッジ時間 8,628 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 574 ms
58,956 KB
testcase_01 AC 118 ms
54,292 KB
testcase_02 AC 120 ms
56,136 KB
testcase_03 AC 117 ms
56,232 KB
testcase_04 AC 128 ms
56,044 KB
testcase_05 AC 129 ms
56,020 KB
testcase_06 AC 132 ms
56,700 KB
testcase_07 AC 132 ms
56,012 KB
testcase_08 AC 129 ms
55,932 KB
testcase_09 AC 129 ms
56,148 KB
testcase_10 AC 132 ms
55,864 KB
testcase_11 AC 131 ms
55,788 KB
testcase_12 AC 157 ms
56,028 KB
testcase_13 AC 131 ms
56,140 KB
testcase_14 AC 179 ms
56,820 KB
testcase_15 AC 155 ms
56,024 KB
testcase_16 AC 177 ms
55,844 KB
testcase_17 AC 178 ms
56,508 KB
testcase_18 AC 132 ms
55,796 KB
testcase_19 AC 163 ms
55,644 KB
testcase_20 AC 173 ms
56,196 KB
testcase_21 AC 535 ms
60,988 KB
testcase_22 AC 594 ms
61,080 KB
evil01.txt AC 571 ms
60,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
       int n = koko.nextInt();
       int[] x = new int[n];
       int[] d = new int[n];
       for(int i = 0; i<n; i++){
           x[i] = koko.nextInt();
       }
       Arrays.sort(x);
       int dis;
       if(n>2){
           dis = x[1]-x[0];
           for(int i = 1; i<n; i++){
               d[i]=x[i]-x[i-1];
               if(dis==0){
                   dis = d[i];
               }else if(dis>d[i]&&d[i]!=0){
                   dis = d[i];
               }
           }
       }else if(n==2){
           dis = x[1]-x[0];
       }else{
           dis = 0;
       }
       System.out.println(dis);
    }
}
0