結果
| 問題 | No.2493 K-th in L2 with L1 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-10-07 04:18:26 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 876 bytes | 
| コンパイル時間 | 1,888 ms | 
| コンパイル使用メモリ | 168,184 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-26 17:41:41 | 
| 合計ジャッジ時間 | 2,052 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 4 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)
int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	int i,j,k;
	int Q;
	cin >> Q;
	while(Q--){
		int D,K;
		cin >> D >> K;
		if(D==0){
			if(K==1){
				cout << "Yes" << endl;
				cout << 0 << ' ' << 0 << endl;
			}else{
				cout << "No" << endl;
			}
			continue;
		}
		bool f=false;
		for(i=0;i<=D/2;i++){
			// P(i,D-i)
			int d=i*i+(D-i)*(D-i);
			int a=0,b=0;
			for(j=0;j<=D;j++){
				int e=j*j+(D-j)*(D-j);
				if(j==0 || j==D){
					if(e<d) a+=2;
					if(e<=d) b+=2;
					continue;
				}
				if(e<d) a+=4;
				if(e<=d) b+=4;
			}
			if(a<K && K<=b){
				f=true;
				cout << "Yes" << endl;
				cout << i << ' ' << D-i << endl;
				break;
			}
		}
		if(!f) cout << "No" << endl;
	}
	return 0;
}
            
            
            
        