結果

問題 No.135 とりあえず1次元の問題
ユーザー ちよちゃんちよちゃん
提出日時 2016-06-06 22:12:31
言語 Java21
(openjdk 21)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,102 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 78,080 KB
最終ジャッジ日時 2024-04-27 02:21:01
合計ジャッジ時間 2,111 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.java:6: error: package org.omg.PortableInterceptor does not exist
import org.omg.PortableInterceptor.Interceptor;
                                  ^
2 errors

ソースコード

diff #

package yukicoder;

import java.util.Arrays;
import java.util.Scanner;

import org.omg.PortableInterceptor.Interceptor;

public class Yuki135 {

	public static void main(String[] args) {

		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();
		}
		scan.close();
		Arrays.sort(x);
		
		int ans = 0;
		int ans2 = 0;
		for (int i = 0; i < n-1; i++) {
			if(x[i] != 0){
				if (x[i + 1] > x[i]) {
					ans = x[i + 1] - x[i];
				} else if(x[i + 1] < x[i]){
					ans = x[i] - x[i + 1];
				} else if(x[i + 1] == x[i]){
					ans = x[i];
				}
				if(ans2 == 0){
					ans2 = ans;
				}else if(ans2 > ans && ans != 0){
					ans2 = ans;
				}
			}
		}
		System.out.println(ans2);

		/*
		 * int ans = 0; int perseAns = 0; for(int i = 0; i < n; i++) { for(int j
		 * = 0; j < n; j++) {
		 * 
		 * if( x[i] > x[j] ){ ans = x[i]-x[j]; } else { ans = x[j]-x[i]; }
		 * 
		 * if(perseAns == 0) { perseAns = ans; }else if ( ans < perseAns && ans
		 * != 0) { perseAns = ans; } } } System.out.println(perseAns);
		 */
	}
}
0