結果
問題 |
No.2803 Bocching Star
|
ユーザー |
![]() |
提出日時 | 2024-07-17 09:32:18 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,188 ms / 2,000 ms |
コード長 | 2,433 bytes |
コンパイル時間 | 3,314 ms |
コンパイル使用メモリ | 91,908 KB |
実行使用メモリ | 86,788 KB |
最終ジャッジ日時 | 2024-07-17 09:32:50 |
合計ジャッジ時間 | 29,246 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int s = sc.nextInt(); TreeSet<Star> stars = new TreeSet<>(); for (int i = 1; i <= n; i++) { stars.add(new Star(i, sc.nextInt())); } stars.add(new Star(0, Integer.MIN_VALUE / 2)); stars.add(new Star(0, Integer.MAX_VALUE)); List<Star> ans = stars.stream() .filter(x -> x.idx != 0 && x.value - stars.lower(x).value > s && stars.higher(x).value - x.value > s) .sorted((a, b) -> a.idx - b.idx) .toList(); System.out.println(ans.size()); System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining(" "))); } static class Star implements Comparable<Star> { int idx; int value; public Star(int idx, int value) { this.idx = idx; this.value = value; } public int hashCode() { return idx; } public boolean equals(Object o) { Star s = (Star)o; return idx == s.idx && value == s.value; } public int compareTo(Star another) { return value == another.value ? idx - another.idx : value - another.value; } public String toString() { return String.valueOf(idx); } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }