結果

問題 No.2368 I love a square root of 2
ユーザー momoyuumomoyuu
提出日時 2023-10-26 12:09:03
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,770 bytes
コンパイル時間 3,212 ms
コンパイル使用メモリ 253,668 KB
実行使用メモリ 5,284 KB
最終ジャッジ日時 2023-10-26 12:09:08
合計ジャッジ時間 5,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 9 ms
4,372 KB
testcase_02 AC 62 ms
5,284 KB
testcase_03 AC 9 ms
4,372 KB
testcase_04 AC 10 ms
4,372 KB
testcase_05 AC 10 ms
4,372 KB
testcase_06 AC 10 ms
4,372 KB
testcase_07 AC 9 ms
4,372 KB
testcase_08 AC 10 ms
4,372 KB
testcase_09 AC 10 ms
4,372 KB
testcase_10 AC 9 ms
4,372 KB
testcase_11 AC 10 ms
4,372 KB
testcase_12 AC 10 ms
4,372 KB
testcase_13 AC 51 ms
5,284 KB
testcase_14 AC 51 ms
5,284 KB
testcase_15 AC 55 ms
5,284 KB
testcase_16 AC 40 ms
5,284 KB
testcase_17 AC 10 ms
4,372 KB
testcase_18 AC 11 ms
4,372 KB
testcase_19 AC 11 ms
4,372 KB
testcase_20 AC 10 ms
4,372 KB
testcase_21 AC 61 ms
5,284 KB
testcase_22 AC 59 ms
5,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

}
0