結果

問題 No.135 とりあえず1次元の問題
ユーザー fujisufujisu
提出日時 2015-01-30 21:41:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 341 ms / 5,000 ms
コード長 2,545 bytes
コンパイル時間 4,022 ms
コンパイル使用メモリ 76,228 KB
実行使用メモリ 62,204 KB
最終ジャッジ日時 2023-08-31 02:08:31
合計ジャッジ時間 6,755 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 331 ms
61,684 KB
testcase_01 AC 42 ms
49,244 KB
testcase_02 AC 42 ms
49,024 KB
testcase_03 AC 42 ms
49,288 KB
testcase_04 AC 45 ms
49,252 KB
testcase_05 AC 44 ms
49,164 KB
testcase_06 AC 44 ms
49,100 KB
testcase_07 AC 44 ms
49,092 KB
testcase_08 AC 44 ms
49,452 KB
testcase_09 AC 44 ms
49,160 KB
testcase_10 AC 45 ms
49,160 KB
testcase_11 AC 45 ms
49,364 KB
testcase_12 AC 55 ms
49,444 KB
testcase_13 AC 46 ms
49,420 KB
testcase_14 AC 70 ms
50,400 KB
testcase_15 AC 55 ms
48,160 KB
testcase_16 AC 91 ms
52,564 KB
testcase_17 AC 80 ms
51,044 KB
testcase_18 AC 49 ms
49,304 KB
testcase_19 AC 80 ms
51,748 KB
testcase_20 AC 65 ms
50,460 KB
testcase_21 AC 204 ms
56,916 KB
testcase_22 AC 341 ms
62,204 KB
evil01.txt AC 330 ms
62,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.util.InputMismatchException;
import java.util.TreeSet;

public class Main {
	void run() {
		MyScanner sc = new MyScanner();
		TreeSet<Integer> set = new TreeSet<Integer>();

		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			set.add(sc.nextInt());
		}

		int pre = set.first();
		set.remove(pre);
		int min = 1 << 25;
		while (!set.isEmpty()) {
			int nxt = set.first();
			set.remove(nxt);
			min = Math.min(min, nxt - pre);
			pre = nxt;
		}

		if (min != 1 << 25) {
			System.out.println(min);
		} else {
			System.out.println(0);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}
0