結果
| 問題 |
No.135 とりあえず1次元の問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-26 22:55:13 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 556 ms / 5,000 ms |
| コード長 | 1,115 bytes |
| コンパイル時間 | 2,950 ms |
| コンパイル使用メモリ | 79,908 KB |
| 実行使用メモリ | 67,320 KB |
| 最終ジャッジ日時 | 2024-06-25 12:13:44 |
| 合計ジャッジ時間 | 8,689 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
package net.ipipip0129.yukicoder.no135;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int cnt = Integer.parseInt(scan.nextLine());
List<Integer> pos_list = new ArrayList<>();
String[] lines = scan.nextLine().split(" ");
for (int i = 0; i < cnt; i++) {
pos_list.add(Integer.parseInt(lines[i]));
}
scan.close();
pos_list = new ArrayList<>(new HashSet<>(pos_list));
Collections.sort(pos_list);
int min_num = -1;
if (pos_list.size() != 1) {
for (int i = 0; i < pos_list.size() - 1; i++) {
if (min_num == -1){
min_num = pos_list.get(i + 1) - pos_list.get(i);
}else if(pos_list.get(i + 1) - pos_list.get(i) < min_num) {
min_num = pos_list.get(i + 1) - pos_list.get(i);
}
}
System.out.println(min_num);
} else {
System.out.println(0);
}
}
}