結果
| 問題 |
No.2354 Poor Sight in Winter
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2023-06-16 22:16:26 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,472 bytes |
| コンパイル時間 | 2,730 ms |
| コンパイル使用メモリ | 77,688 KB |
| 実行使用メモリ | 264,536 KB |
| 最終ジャッジ日時 | 2024-06-24 14:45:57 |
| 合計ジャッジ時間 | 6,709 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 25 |
ソースコード
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] x = new int[n + 2];
int[] y = new int[n + 2];
x[0] = sc.nextInt();
y[0] = sc.nextInt();
x[n + 1] = sc.nextInt();
y[n + 1] = sc.nextInt();
for (int i = 1; i <= n; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
sc.close();
int ok = 200000;
int ng = 0;
while (Math.abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
PriorityQueue<Node> que = new PriorityQueue<Node>();
Node first = new Node(0, 0);
que.add(first);
int[] d = new int[n + 2];
Arrays.fill(d, 1000000007);
d[0] = 0;
while (!que.isEmpty()) {
Node cur = que.poll();
if (cur.d > d[cur.v]) {
continue;
}
for (int next = 1; next <= n + 1; next++) {
int v1 = Math.abs(x[cur.v] - x[next])
+ Math.abs(y[cur.v] - y[next]);
int alt = d[cur.v] + (v1 - 1) / mid;
if (alt < d[next]) {
d[next] = alt;
que.add(new Node(next, alt));
}
}
}
if (d[n + 1] <= k) {
ok = mid;
} else {
ng = mid;
}
}
System.out.println(ok);
}
static class Node implements Comparable<Node> {
int v;
long d;
public Node(int v, long d) {
this.v = v;
this.d = d;
}
public int compareTo(Node o) {
return Long.compare(d, o.d);
}
}
}
ks2m