結果

問題 No.2493 K-th in L2 with L1
ユーザー binapbinap
提出日時 2023-10-06 21:50:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,554 bytes
コンパイル時間 4,534 ms
コンパイル使用メモリ 267,380 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-06 21:50:56
合計ジャッジ時間 5,059 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> P;
typedef long double ld;

template<typename T>
istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}

void solve(){
	int d, k;
	cin >> d >> k;
	if(d == 0){
		if(k == 1) cout << "Yes\n0 0\n";
		else cout << "No\n";
		return;
	}
	if(k > 4 * d){
		cout << "No\n";
		return;
	}
	vector<tuple<int, int, int>> a;
	rep(x, d){
		int y = d - x;
		a.emplace_back(x * x + y * y, x, y);
	}
	for(int y = 0; y > -d; y--){
		int x = d + y;
		a.emplace_back(x * x + y * y, x, y);
	}
	for(int x = 0; x > -d; x--){
		int y = -d - x;
		a.emplace_back(x * x + y * y, x, y);
	}
	rep(y, d){
		int x = -d + y;
		a.emplace_back(x * x + y * y, x, y);
	}
	sort(a.begin(), a.end());
	/*
	for(auto [tmp, x, y] : a){
		cout << x << ' ' << y << "\n";
	}
	*/
	auto [tmp, x, y] = a[k - 1];
	cout << "Yes\n";
	cout << x << ' ' << y << "\n";
}

int main(){
	int t;
	cin >> t;
	rep(_, t) solve();
	return 0;
}
0