結果

問題 No.135 とりあえず1次元の問題
ユーザー YukimotoPGYukimotoPG
提出日時 2019-03-01 11:43:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 2,496 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 75,448 KB
実行使用メモリ 53,756 KB
最終ジャッジ日時 2023-09-05 16:31:04
合計ジャッジ時間 4,655 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
53,732 KB
testcase_01 AC 43 ms
49,400 KB
testcase_02 AC 42 ms
49,516 KB
testcase_03 AC 43 ms
49,556 KB
testcase_04 AC 43 ms
49,432 KB
testcase_05 AC 43 ms
49,240 KB
testcase_06 AC 42 ms
49,368 KB
testcase_07 AC 43 ms
49,272 KB
testcase_08 AC 42 ms
49,480 KB
testcase_09 AC 42 ms
49,540 KB
testcase_10 AC 42 ms
49,336 KB
testcase_11 AC 44 ms
49,564 KB
testcase_12 AC 42 ms
49,380 KB
testcase_13 AC 43 ms
49,188 KB
testcase_14 AC 45 ms
49,588 KB
testcase_15 AC 44 ms
49,284 KB
testcase_16 AC 46 ms
49,284 KB
testcase_17 AC 45 ms
49,764 KB
testcase_18 AC 42 ms
49,424 KB
testcase_19 AC 45 ms
49,388 KB
testcase_20 AC 44 ms
49,180 KB
testcase_21 AC 103 ms
53,108 KB
testcase_22 AC 157 ms
53,756 KB
evil01.txt AC 157 ms
53,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.stream.*;
import static java.lang.System.*;
import java.io.*;

class Main {
//	static Scanner sc = new Scanner(System.in);
	static int maxInt = Integer.MAX_VALUE;
	static int minInt = Integer.MIN_VALUE;
//	static int nextInt () {return Integer.parseInt(sc.next());}
//	static int[] nextIntArray (int n) {return IntStream.range(0,n).map(i->nextInt()).toArray();}
	static int max (int... ar) {Arrays.sort(ar);return ar[ar.length-1];}
	static int min (int... ar) {Arrays.sort(ar);return ar[0];}
	
	
	static FastScanner sc = new FastScanner();
	public static void main(String[] args) {
		//MAIN----------------------------------------------------------
		
		int n = sc.nextInt();
		if (n == 1) {
			System.out.println(0); return;
		}
		else {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = sc.nextInt();
			Arrays.sort(ar);
			int min = Integer.MAX_VALUE;
			for (int i=1; i<n; i++) {
				if (ar[i]-ar[i-1] != 0) {
					min = Math.min(min, ar[i]-ar[i-1]);
				}
			}
			System.out.println(min==Integer.MAX_VALUE?0:min);
		}
		
		//--------------------------------------------------------------
	}
}


class FastScanner {
	private InputStream in = System.in;
	private byte[] buffer = new byte[10];
	private int length = 0;
	private int p = 0;

	boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}

	int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}

	boolean isPrintable (int n) {return 33<=n&&n<=126;}
	void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	boolean hasNext () {skip(); return hasNextByte();}
	
	String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	
	int nextInt () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		int n = 0;
		while (true) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			else if (temp==-1 || !isPrintable(temp)) {
				return minus? -n : n;
			}
			else {
				throw new NumberFormatException();
			}
			temp = readByte();
		}
	}
}






















0