結果

問題 No.2493 K-th in L2 with L1
ユーザー kotatsugamekotatsugame
提出日時 2023-10-06 21:24:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 815 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 83,824 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-06 21:24:44
合計ジャッジ時間 1,476 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int Q;cin>>Q;
	for(;Q--;)
	{
		int D,K;
		cin>>D>>K;
		vector<pair<int,int> >X;
		for(int x=0;x<=D;x++)
		{
			int y=D-x;
			X.push_back(make_pair(x,y));
			X.push_back(make_pair(x,-y));
			X.push_back(make_pair(-x,y));
			X.push_back(make_pair(-x,-y));
		}
		sort(X.begin(),X.end());
		X.erase(unique(X.begin(),X.end()),X.end());
		vector<pair<int,pair<int,int> > >A(X.size());
		for(int i=0;i<X.size();i++)
		{
			A[i].second=X[i];
			A[i].first=X[i].first*X[i].first+X[i].second*X[i].second;
		}
		sort(A.begin(),A.end());
		if(A.size()<K)cout<<"No\n";
		else
		{
			cout<<"Yes\n";
			cout<<A[K-1].second.first<<" "<<A[K-1].second.second<<"\n";
		}
	}
}
0