結果

問題 No.2493 K-th in L2 with L1
ユーザー daiotadaiota
提出日時 2023-10-07 04:18:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 1,881 ms
コンパイル使用メモリ 166,356 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-10-07 04:18:28
合計ジャッジ時間 2,355 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0