結果

問題 No.2493 K-th in L2 with L1
ユーザー ks2mks2m
提出日時 2023-10-06 22:01:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 78,936 KB
実行使用メモリ 59,164 KB
最終ジャッジ日時 2023-10-06 22:01:53
合計ジャッジ時間 4,463 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
56,780 KB
testcase_01 AC 239 ms
59,068 KB
testcase_02 AC 235 ms
58,924 KB
testcase_03 AC 263 ms
59,164 KB
testcase_04 AC 158 ms
57,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 q = sc.nextInt();
		for (int z = 0; z < q; z++) {
			int d = sc.nextInt();
			int k = sc.nextInt();
			PriorityQueue<Obj> que = new PriorityQueue<>(
					(o1, o2) -> Double.compare(o1.d, o2.d));
			if (d == 0) {
				que.add(new Obj(0, 0, 0));
			} else {
				for (int i = 0; i < d; i++) {
					que.add(new Obj(i, d - i, Math.hypot(i, d - i)));
					que.add(new Obj(d - i, -i, Math.hypot(d - i, -i)));
					que.add(new Obj(-i, i - d, Math.hypot(-i, i - d)));
					que.add(new Obj(i - d, i, Math.hypot(i - d, i)));
				}
			}
			if (que.size() < k) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
				for (int i = 1; i < k; i++) {
					que.poll();
				}
				Obj o = que.poll();
				System.out.println(o.x + " " + o.y);
			}
		}
		sc.close();
	}

	static class Obj {
		int x, y;
		double d;

		public Obj(int x, int y, double d) {
			this.x = x;
			this.y = y;
			this.d = d;
		}
	}
}
0