結果

問題 No.135 とりあえず1次元の問題
ユーザー YamaKasaYamaKasa
提出日時 2018-04-25 01:29:57
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,508 bytes
コンパイル時間 4,845 ms
コンパイル使用メモリ 76,540 KB
実行使用メモリ 66,988 KB
最終ジャッジ日時 2023-09-10 05:14:05
合計ジャッジ時間 11,418 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 705 ms
66,988 KB
testcase_01 AC 126 ms
56,108 KB
testcase_02 AC 126 ms
55,912 KB
testcase_03 RE -
testcase_04 AC 136 ms
58,208 KB
testcase_05 AC 135 ms
56,432 KB
testcase_06 AC 136 ms
56,412 KB
testcase_07 AC 137 ms
56,072 KB
testcase_08 AC 137 ms
55,968 KB
testcase_09 AC 136 ms
56,248 KB
testcase_10 AC 137 ms
55,652 KB
testcase_11 AC 136 ms
55,780 KB
testcase_12 AC 156 ms
56,092 KB
testcase_13 AC 138 ms
53,820 KB
testcase_14 AC 192 ms
54,380 KB
testcase_15 AC 155 ms
55,800 KB
testcase_16 AC 191 ms
56,104 KB
testcase_17 AC 188 ms
55,944 KB
testcase_18 AC 144 ms
55,988 KB
testcase_19 AC 186 ms
56,136 KB
testcase_20 AC 177 ms
56,428 KB
testcase_21 AC 591 ms
62,908 KB
testcase_22 AC 716 ms
66,852 KB
evil01.txt AC 644 ms
63,824 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; i++) {
			if(list.get(i) == list.get(i + 1)) {
				k ++;
			}else {
				break;
			}
		}
		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