結果
| 問題 | No.2493 K-th in L2 with L1 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-10-06 21:33:15 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 72 ms / 2,000 ms | 
| コード長 | 894 bytes | 
| コンパイル時間 | 171 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 72,128 KB | 
| 最終ジャッジ日時 | 2024-07-26 15:48:43 | 
| 合計ジャッジ時間 | 1,100 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 4 | 
ソースコード
import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd
q = int(input())
dk = [list(map(int,input().split())) for i in range(q)]
def eu(x,y):
    return x**2 + y**2
for d,k in dk:
    pos = []
    if d == 0:
        if k == 1:
            print('Yes')
            print(0,0)
        else:
            print('No')
        continue
    for x in range(d+1):
        y = d-abs(x)
        pos.append([eu(x,y),x*1000+y])
        pos.append([eu(x,y),x*1000+y])
        if x != 0 and y != 0:
            pos.append([eu(x,y),x*1000+y])
            pos.append([eu(x,y),x*1000+y])
    pos.sort()
    if len(pos) >= k >= 1:
        ans = pos[k-1][1]
        print('Yes')
        print(ans//1000, ans%1000)
    else:
        print('No')
            
            
            
        