結果

問題 No.2368 I love a square root of 2
ユーザー kotatsugamekotatsugame
提出日時 2023-07-01 03:48:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,077 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 77,448 KB
実行使用メモリ 11,472 KB
最終ジャッジ日時 2023-09-21 21:42:38
合計ジャッジ時間 2,534 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,472 KB
testcase_01 AC 4 ms
6,472 KB
testcase_02 AC 39 ms
10,812 KB
testcase_03 AC 4 ms
6,588 KB
testcase_04 AC 4 ms
6,524 KB
testcase_05 AC 4 ms
6,508 KB
testcase_06 AC 4 ms
6,520 KB
testcase_07 AC 5 ms
6,512 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 5 ms
6,472 KB
testcase_10 AC 4 ms
6,504 KB
testcase_11 AC 4 ms
6,528 KB
testcase_12 AC 4 ms
6,584 KB
testcase_13 AC 32 ms
11,472 KB
testcase_14 AC 31 ms
11,104 KB
testcase_15 AC 35 ms
10,468 KB
testcase_16 AC 24 ms
8,292 KB
testcase_17 AC 4 ms
6,768 KB
testcase_18 AC 5 ms
6,592 KB
testcase_19 AC 5 ms
6,692 KB
testcase_20 AC 5 ms
6,584 KB
testcase_21 AC 39 ms
10,552 KB
testcase_22 AC 37 ms
10,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
const int LIM=2e5;
long B[LIM];
long cnt[LIM];
bool f(pair<long,long>p,pair<long,long>q)
{//p<q
	long a=p.first,b=p.second;
	long c=q.first,d=q.second;
	if(a-c<0)
	{
		if(d-b<0)return (a-c)*(a-c)>2*(d-b)*(d-b);
		else return true;
	}
	else
	{
		if(d-b<0)return false;
		else return (a-c)*(a-c)<2*(d-b)*(d-b);
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	B[0]=1;
	cnt[0]=1;
	for(int c=1;c<LIM;c++)
	{
		long b=B[c-1]-1;
		long d=(long)c*c;
		while(2*(b+1)*(b+1)<=d)b++;
		B[c]=b+1;
		cnt[c]=cnt[c-1]+B[c];
	}
	long N;cin>>N;
	if(N==1)
	{
		cout<<"0 0\n";
		return 0;
	}
	N-=1;
	long R=0;
	long b=0;
	while(true)
	{
		R++;
		while(2*(b+1)*(b+1)<=R*R)b++;
		if(N<=b+1)break;
		N-=b+1;
	}
	vector<pair<long,long> >A;
	long a=R;b=0;
	A.push_back(make_pair(a,b));
	while(a>0)
	{
		a--;
		if(!f(make_pair(R-1,0),make_pair(a,b)))b++;
		A.push_back(make_pair(a,b));
	}
	sort(A.begin(),A.end(),f);
	assert(N<=A.size());
	cout<<A[N-1].first<<" "<<A[N-1].second<<endl;
}
0