結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 708 ms
66,292 KB
testcase_01 AC 125 ms
55,976 KB
testcase_02 AC 124 ms
55,968 KB
testcase_03 RE -
testcase_04 AC 133 ms
55,960 KB
testcase_05 AC 136 ms
55,740 KB
testcase_06 AC 135 ms
55,768 KB
testcase_07 AC 136 ms
55,932 KB
testcase_08 AC 133 ms
55,660 KB
testcase_09 AC 137 ms
55,936 KB
testcase_10 AC 134 ms
56,396 KB
testcase_11 AC 134 ms
54,300 KB
testcase_12 AC 161 ms
55,928 KB
testcase_13 AC 137 ms
55,948 KB
testcase_14 AC 187 ms
56,312 KB
testcase_15 AC 155 ms
56,112 KB
testcase_16 AC 185 ms
56,116 KB
testcase_17 AC 190 ms
56,532 KB
testcase_18 AC 142 ms
56,072 KB
testcase_19 AC 188 ms
57,012 KB
testcase_20 AC 185 ms
56,028 KB
testcase_21 AC 593 ms
62,876 KB
testcase_22 AC 720 ms
66,376 KB
evil01.txt AC 654 ms
64,112 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;
			}
		}
		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