結果

問題 No.2368 I love a square root of 2
ユーザー i_am_noobi_am_noob
提出日時 2023-06-30 22:59:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,111 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 205,216 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 17:15:11
合計ジャッジ時間 3,551 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,376 KB
testcase_01 AC 5 ms
4,380 KB
testcase_02 AC 36 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 28 ms
4,376 KB
testcase_14 AC 30 ms
4,380 KB
testcase_15 AC 31 ms
4,376 KB
testcase_16 AC 22 ms
4,380 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 35 ms
4,380 KB
testcase_22 AC 34 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
}
0