結果

問題 No.2368 I love a square root of 2
ユーザー kotatsugamekotatsugame
提出日時 2023-06-30 23:06:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 77,312 KB
実行使用メモリ 12,112 KB
最終ジャッジ日時 2023-09-21 17:23:21
合計ジャッジ時間 2,326 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,496 KB
testcase_01 AC 5 ms
6,480 KB
testcase_02 AC 41 ms
11,436 KB
testcase_03 AC 5 ms
6,496 KB
testcase_04 AC 4 ms
6,560 KB
testcase_05 AC 4 ms
6,528 KB
testcase_06 AC 5 ms
6,508 KB
testcase_07 AC 5 ms
6,560 KB
testcase_08 AC 4 ms
6,512 KB
testcase_09 AC 5 ms
6,508 KB
testcase_10 AC 4 ms
6,836 KB
testcase_11 AC 4 ms
6,616 KB
testcase_12 AC 4 ms
6,588 KB
testcase_13 AC 34 ms
11,556 KB
testcase_14 AC 34 ms
12,084 KB
testcase_15 AC 36 ms
11,440 KB
testcase_16 AC 24 ms
8,500 KB
testcase_17 AC 4 ms
6,616 KB
testcase_18 AC 5 ms
6,612 KB
testcase_19 AC 5 ms
6,608 KB
testcase_20 AC 5 ms
6,744 KB
testcase_21 AC 40 ms
12,112 KB
testcase_22 AC 39 ms
10,888 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;
	}
	long L=0,R=LIM-1;
	while(R-L>1)
	{
		long mid=(L+R)/2;
		if(cnt[mid]>=N)R=mid;
		else L=mid;
	}
	vector<pair<long,long> >A;
	N-=cnt[L];
	long a=R,b=0;
	A.push_back(make_pair(a,b));
	while(a>0)
	{
		a--;
		if(!f(make_pair(L,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