結果
問題 |
No.2368 I love a square root of 2
|
ユーザー |
![]() |
提出日時 | 2023-10-26 12:09:03 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 1,770 bytes |
コンパイル時間 | 3,217 ms |
コンパイル使用メモリ | 252,880 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-25 12:22:13 |
合計ジャッジ時間 | 4,726 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; bool isb(ll a,ll b,ll c,ll d){ // return a + br2 < c + dr2 ll da = c - a; ll db = d - b; if(da<=0&&db<=0) return 0; if(da>=0&&db>=0) return 1; if(da==0) return db > 0; if(db==0) return da > 0; if(da<0){ da *= da; db *= db; return da < 2 * db; }else{ assert(db<0); db *= db; da *= da; return 2 * db < da; } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin>>n; if(n==1){ cout<<0<<" "<<0<<endl; return 0; } ll right = 1e6; ll left = -1; while(right-left>1){ ll mid = (right+left) / 2; //mid >= x ll cnt = 0; ll can = mid; //mid >= i + can r2 for(ll i = 0;i<=mid;i++){ while(isb(mid,0,i,can)) can--; assert(can>=0); cnt += can + 1; } if(cnt<n) left = mid; else right = mid; } // n <= #x<=right // left < ans <= right // left <= a + b r2 <= right assert(left>=0); ll can = left; ll cnt = 0; for(ll i = 0;i<=left;i++){ while(isb(left,0,i,can)) can--; cnt += can + 1; } ll need = n - cnt; assert(need>0); vector<pair<ll,ll>> use; can = left; for(ll i = 0;i<=left;i++){ while(isb(left,0,i,can-1)) can--; assert(can>=0); if(isb(i,can,right,0)) use.push_back(make_pair(i,can)); } sort(use.begin(),use.end(),[&](pair<ll,ll>a,pair<ll,ll> b){ return isb(a.first,a.second,b.first,b.second);}); need--; if(need<use.size()) cout<<use[need].first<<" "<<use[need].second<<endl; else cout<<right<<" "<<0<<endl; }