結果

問題 No.2368 I love a square root of 2
ユーザー 沙耶花沙耶花
提出日時 2023-06-30 22:41:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 424 ms / 2,000 ms
コード長 1,678 bytes
コンパイル時間 4,482 ms
コンパイル使用メモリ 264,864 KB
実行使用メモリ 9,040 KB
最終ジャッジ日時 2023-09-21 16:51:21
合計ジャッジ時間 10,569 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 150 ms
4,376 KB
testcase_02 AC 424 ms
8,508 KB
testcase_03 AC 150 ms
4,376 KB
testcase_04 AC 151 ms
4,380 KB
testcase_05 AC 151 ms
4,380 KB
testcase_06 AC 150 ms
4,376 KB
testcase_07 AC 150 ms
4,376 KB
testcase_08 AC 150 ms
4,380 KB
testcase_09 AC 150 ms
4,376 KB
testcase_10 AC 151 ms
4,380 KB
testcase_11 AC 151 ms
4,376 KB
testcase_12 AC 150 ms
4,380 KB
testcase_13 AC 369 ms
7,964 KB
testcase_14 AC 374 ms
9,040 KB
testcase_15 AC 391 ms
7,656 KB
testcase_16 AC 305 ms
5,452 KB
testcase_17 AC 152 ms
4,376 KB
testcase_18 AC 155 ms
4,376 KB
testcase_19 AC 155 ms
4,376 KB
testcase_20 AC 155 ms
4,380 KB
testcase_21 AC 419 ms
7,444 KB
testcase_22 AC 413 ms
8,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

long long get(long long n){
	long long ok = 0,ng = 2000000;
	while(ng-ok>1LL){
		long long mid = (ok+ng)/2;
		if(mid*mid*2<=n)ok = mid;
		else ng = mid;
	}
	return ok+1;
}

long long get2(long long n){
	long long ng=  -1,ok  = 1e9;
	while(ok-ng>1LL){
		long long mid = (ok+ng)/2;
		if(mid*mid*2>n)ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(){
	
	long long N;
	cin>>N;
	if(N==1){
		cout<<0<<' '<<0<<endl;
		return 0;
	}
	long long ok = 0,ng = 2000000;
	while(ng-ok>1LL){
		
		long long mid = (ok+ng)/2;
		long long sum = 0;
		for(long long i=0;i<=mid;i++){
			long long cur = mid - i;
			cur *= cur;
			sum += get(cur);
		}
		if(sum<N)ok = mid;
		else ng = mid;
	}
	//cout<<ok<<endl;
	for(long long i=0;i<=ok;i++){
		long long cur = ok - i;
		cur *= cur;
		N -= get(cur);
		//P.emplace_back(i,get2(cur));
	}
	//cout<<N<<endl;
	vector<pair<long long,long long>> P;
	for(long long i=0;i<=ok+10;i++){
		long long cur = ok-i;
		if(cur<0){
			P.emplace_back(i,0);
			continue;
		}
		cur *= cur;
		P.emplace_back(i,get2(cur));
		//cout<<i<<','<<get2(cur)<<endl;
	}
	sort(P.begin(),P.end(),[&](pair<long long,long long> a,pair<long long,long long> b){
		long long x = a.first - b.first,y = b.second - a.second;
		if(x<0&&y>=0)return true;
		if(y<0&&x>=0)return false;
		if(x>=0&&y>=0){
			return x*x < y*y*2;
		}
		else{
			return x*x > y*y*2;
		}
		
	});
	
	cout<<P[N-1].first<<' '<<P[N-1].second<<endl;
	
    return 0;
}

0