結果

問題 No.2493 K-th in L2 with L1
ユーザー ks2m
提出日時 2023-10-06 22:01:49
言語 Java
(openjdk 23)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 81,060 KB
実行使用メモリ 57,656 KB
最終ジャッジ日時 2024-07-26 16:07:16
合計ジャッジ時間 4,199 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

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