結果

問題 No.2354 Poor Sight in Winter
ユーザー ks2mks2m
提出日時 2023-06-16 22:23:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 1,307 bytes
コンパイル時間 3,157 ms
コンパイル使用メモリ 76,324 KB
実行使用メモリ 57,184 KB
最終ジャッジ日時 2023-09-06 20:34:31
合計ジャッジ時間 9,521 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,416 KB
testcase_01 AC 123 ms
55,488 KB
testcase_02 AC 124 ms
56,016 KB
testcase_03 AC 125 ms
55,920 KB
testcase_04 AC 129 ms
55,672 KB
testcase_05 AC 128 ms
53,448 KB
testcase_06 AC 127 ms
55,320 KB
testcase_07 AC 123 ms
53,348 KB
testcase_08 AC 126 ms
55,184 KB
testcase_09 AC 126 ms
55,320 KB
testcase_10 AC 126 ms
55,360 KB
testcase_11 AC 250 ms
57,084 KB
testcase_12 AC 300 ms
57,100 KB
testcase_13 AC 284 ms
54,920 KB
testcase_14 AC 302 ms
56,388 KB
testcase_15 AC 278 ms
57,128 KB
testcase_16 AC 297 ms
56,752 KB
testcase_17 AC 285 ms
56,656 KB
testcase_18 AC 244 ms
56,944 KB
testcase_19 AC 260 ms
57,184 KB
testcase_20 AC 228 ms
56,844 KB
testcase_21 AC 179 ms
56,412 KB
testcase_22 AC 216 ms
56,616 KB
testcase_23 AC 206 ms
56,464 KB
testcase_24 AC 276 ms
57,052 KB
testcase_25 AC 202 ms
56,968 KB
testcase_26 AC 198 ms
56,412 KB
testcase_27 AC 139 ms
55,560 KB
testcase_28 AC 187 ms
56,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
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[] d = new int[n + 2];
		boolean[] fix = new boolean[n + 2];
		int ok = 200000;
		int ng = 0;
		while (Math.abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;

			Arrays.fill(d, 1000000007);
			d[0] = 0;
			Arrays.fill(fix, false);
			fix[0] = true;
			while (true) {
				int min = 1000000007;
				int cur = 0;
				for (int i = 0; i < d.length; i++) {
					if (!fix[i] && d[i] < min) {
						min = d[i];
						cur = i;
					}
				}
				if (cur == n + 1) {
					break;
				}
				fix[cur] = true;
				for (int next = 1; next <= n + 1; next++) {
					int v1 = Math.abs(x[cur] - x[next])
							+ Math.abs(y[cur] - y[next]);
					int alt = d[cur] + (v1 - 1) / mid;
					if (alt < d[next]) {
						d[next] = alt;
					}
				}
			}

			if (d[n + 1] <= k) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		System.out.println(ok);
	}
}
0