結果
問題 | No.2923 Mayor's Job |
ユーザー | tenten |
提出日時 | 2024-10-21 10:16:39 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 2,498 bytes |
コンパイル時間 | 2,339 ms |
コンパイル使用メモリ | 79,392 KB |
実行使用メモリ | 52,980 KB |
最終ジャッジ日時 | 2024-10-21 10:16:45 |
合計ジャッジ時間 | 5,504 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
50,528 KB |
testcase_01 | AC | 52 ms
50,044 KB |
testcase_02 | AC | 52 ms
50,200 KB |
testcase_03 | AC | 158 ms
52,876 KB |
testcase_04 | AC | 105 ms
52,416 KB |
testcase_05 | AC | 138 ms
52,912 KB |
testcase_06 | AC | 147 ms
52,900 KB |
testcase_07 | AC | 135 ms
52,864 KB |
testcase_08 | AC | 126 ms
52,832 KB |
testcase_09 | AC | 125 ms
52,980 KB |
testcase_10 | AC | 130 ms
52,756 KB |
testcase_11 | AC | 114 ms
52,560 KB |
testcase_12 | AC | 116 ms
52,520 KB |
testcase_13 | AC | 78 ms
51,388 KB |
testcase_14 | AC | 58 ms
50,528 KB |
testcase_15 | AC | 51 ms
50,288 KB |
testcase_16 | AC | 52 ms
50,432 KB |
testcase_17 | AC | 52 ms
50,512 KB |
testcase_18 | AC | 51 ms
50,540 KB |
testcase_19 | AC | 51 ms
50,172 KB |
ソースコード
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 k = sc.nextInt(); House[] houses = new House[n]; for (int i = 0; i < n; i++) { houses[i] = new House(sc.nextInt()); } for (int i = 0; i < n; i++) { houses[i].point = new Point(sc.nextInt(), sc.nextInt()); } Arrays.sort(houses); long d2 = (long)k * k; int ans = 0; for (int i = 0; i < n; i++) { boolean enable = false; for (int j = i + 1; j < n && !enable; j++) { enable = houses[i].histry < houses[j].histry && houses[i].getDistance2(houses[j]) <= d2; } if (!enable) { ans++; } } System.out.println(ans); } static class House implements Comparable<House> { int histry; Point point; public House(int histry) { this.histry = histry; } public long getDistance2(House h) { return point.getDistance2(h.point); } public int compareTo(House another) { return histry - another.histry; } } static class Point { long x; long y; public Point(long x, long y) { this.x = x; this.y = y; } public long getDistance2(Point p) { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y); } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); 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(); } } }