結果
問題 | No.2368 I love a square root of 2 |
ユーザー |
|
提出日時 | 2023-06-30 22:59:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 2,008 ms |
コンパイル使用メモリ | 200,596 KB |
最終ジャッジ日時 | 2025-02-15 04:30:07 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; using pii=pair<int,int>; #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) ((int)a.size()) const int N=1000005; ll calc(int n){// count < n ll res=0; for(int i=0; i<=n; ++i){ ll de=2ll*i*i; ll x=sqrt(de)+3; while((x-1)*(x-1)>de) x--; if(x>n) break; res+=n+1-x; } return res; } bool cmp(pii a, pii b){ int x=a.first-b.first,y=b.second-a.second; if(x>=0&&y<0) return 0; if(x<0&&y>=0) return 1; ll xx=1ll*x*x,yy=2ll*y*y; if(xx==yy) return 0; return (xx>yy)^(x>=0); } signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); ll n; cin >> n; int l=0,r=N; while(l<r){ int mid=l+r+1>>1; if(calc(mid)>=n) r=mid-1; else l=mid; } vector<pii> vec; for(int i=0; i<=l; ++i){ ll de=2ll*i*i; ll x=sqrt(de)+3; while(x*x>de) x--; if(x>l) break; vec.pb({l-x,i}); } sort(all(vec),cmp); n-=calc(l)+1; cout << vec[n].first << ' ' << vec[n].second << "\n"; }