結果

問題 No.135 とりあえず1次元の問題
ユーザー YamaKasaYamaKasa
提出日時 2018-04-25 01:32:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 745 ms / 5,000 ms
コード長 1,582 bytes
コンパイル時間 3,716 ms
コンパイル使用メモリ 79,592 KB
実行使用メモリ 67,308 KB
最終ジャッジ日時 2023-09-10 05:14:40
合計ジャッジ時間 9,980 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 743 ms
67,308 KB
testcase_01 AC 124 ms
56,068 KB
testcase_02 AC 124 ms
55,716 KB
testcase_03 AC 123 ms
55,596 KB
testcase_04 AC 134 ms
55,696 KB
testcase_05 AC 136 ms
56,092 KB
testcase_06 AC 137 ms
55,776 KB
testcase_07 AC 135 ms
57,952 KB
testcase_08 AC 136 ms
55,896 KB
testcase_09 AC 137 ms
55,712 KB
testcase_10 AC 137 ms
56,124 KB
testcase_11 AC 135 ms
55,444 KB
testcase_12 AC 159 ms
56,056 KB
testcase_13 AC 142 ms
55,804 KB
testcase_14 AC 195 ms
57,188 KB
testcase_15 AC 159 ms
56,116 KB
testcase_16 AC 196 ms
56,320 KB
testcase_17 AC 194 ms
56,080 KB
testcase_18 AC 147 ms
55,704 KB
testcase_19 AC 194 ms
56,980 KB
testcase_20 AC 189 ms
56,000 KB
testcase_21 AC 608 ms
62,812 KB
testcase_22 AC 745 ms
66,788 KB
evil01.txt AC 687 ms
64,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		//int []X = new int[N];
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		scan.close();
		if(N == 1) {
			System.out.println("0");
			System.exit(0);
		}
		Collections.sort(list);

		int k = 0;
		for(int i = 0; i < N - 1; i++) {
			if(list.get(i) == list.get(i + 1)) {
				k ++;
			}else {
				break;
			}
		}
		if(k == N - 1) {
			System.out.println("0");
			System.exit(0);
		}
		int ans = list.get(k) - list.get(k + 1);
		if(ans < 0) {
			ans = - ans;
		}
		int temp = 0;
		for(int i = k + 1; i < N - 1; i++) {
			int x1 = list.get(i);
			int x2 = list.get(i + 1);
			temp = x1 - x2;
			if(temp != 0) {
				if(temp < 0) {
					temp = - temp;
				}
				if(ans > temp) {
					ans = temp;
				}
			}
		}
//		Arrays.sort(X);
//		int k = 0;
//		for(int i = 0; i < N - 1; i++) {
//			if(X[i] == X[i + 1]) {
//				k ++;
//			}else {
//				break;
//			}
//		}
//		if(k == N - 1) {
//			System.out.println("0");
//			System.exit(0);
//		}
//		int ans = X[k] - X[k + 1];
//		if(ans < 0) {
//			ans = - ans;
//		}
//		int temp = 0;
//		for(int i = k + 1; i < N - 1; i++) {
//			int x1 = X[i];
//			int x2 = X[i + 1];
//			temp = x1 - x2;
//			if(temp != 0) {
//				if(temp < 0) {
//					temp = - temp;
//				}
//				if(ans > temp) {
//					ans = temp;
//				}
//			}
//		}
		System.out.println(ans);
	}
}
0