結果
| 問題 |
No.2923 Mayor's Job
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-10-21 10:16:39 |
| 言語 | Java (openjdk 23) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
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();
}
}
}
tenten