結果

問題 No.2420 Simple Problem
ユーザー InTheBloomInTheBloom
提出日時 2024-03-05 14:58:58
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,057 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 3,637 ms
コンパイル使用メモリ 352,904 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-05 14:59:38
合計ジャッジ時間 34,791 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 412 ms
6,676 KB
testcase_02 AC 5 ms
6,676 KB
testcase_03 AC 150 ms
6,676 KB
testcase_04 AC 796 ms
6,676 KB
testcase_05 AC 512 ms
6,676 KB
testcase_06 AC 1,027 ms
6,676 KB
testcase_07 AC 998 ms
6,676 KB
testcase_08 AC 1,005 ms
6,676 KB
testcase_09 AC 1,021 ms
6,676 KB
testcase_10 AC 1,022 ms
6,676 KB
testcase_11 AC 998 ms
6,676 KB
testcase_12 AC 997 ms
6,676 KB
testcase_13 AC 1,057 ms
6,676 KB
testcase_14 AC 1,020 ms
6,676 KB
testcase_15 AC 1,000 ms
6,676 KB
testcase_16 AC 1,000 ms
6,676 KB
testcase_17 AC 1,020 ms
6,676 KB
testcase_18 AC 1,022 ms
6,676 KB
testcase_19 AC 998 ms
6,676 KB
testcase_20 AC 1,020 ms
6,676 KB
testcase_21 AC 1,029 ms
6,676 KB
testcase_22 AC 1,001 ms
6,676 KB
testcase_23 AC 1,019 ms
6,676 KB
testcase_24 AC 1,000 ms
6,676 KB
testcase_25 AC 1,026 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 795 ms
6,676 KB
testcase_28 AC 806 ms
6,676 KB
testcase_29 AC 797 ms
6,676 KB
testcase_30 AC 793 ms
6,676 KB
testcase_31 AC 796 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 415 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
using namespace boost::multiprecision;

ll solve (int A, int B) {
    auto f = [&](ll X) -> bool {
        cpp_int a = A, b = B, x = X;

        return 0 < x*x - a - b && 4 * a * b < (x*x - (a+b)) * (x*x - (a+b));
    };

    ll ok = 65000, ng = 0;
    while (1 < abs(ok-ng)) {
        ll mid = (ok + ng) / 2;
        if (f(mid)) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }

    return ok;
}

int main () {
    int N; cin >> N;
    // 二回2乗してやれば二分探索できそうな形になる(った)
    // -> アッ、二乗したときに符号関連の情報が死んでるっぽい

    while (N--) {
        int A, B; cin >> A >> B;

        auto ans = solve(A, B);
        cout << ans << "\n";
    }
}
0