結果

問題 No.2420 Simple Problem
ユーザー Kyoro IDKyoro ID
提出日時 2023-08-13 09:22:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 580 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 95,924 KB
最終ジャッジ日時 2024-05-01 02:58:01
合計ジャッジ時間 20,107 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,664 KB
testcase_01 AC 298 ms
85,172 KB
testcase_02 AC 102 ms
79,300 KB
testcase_03 AC 180 ms
82,008 KB
testcase_04 AC 493 ms
91,532 KB
testcase_05 AC 341 ms
86,456 KB
testcase_06 AC 563 ms
95,664 KB
testcase_07 AC 564 ms
95,424 KB
testcase_08 AC 564 ms
95,660 KB
testcase_09 AC 551 ms
95,792 KB
testcase_10 AC 571 ms
95,916 KB
testcase_11 AC 579 ms
95,408 KB
testcase_12 AC 572 ms
95,660 KB
testcase_13 AC 564 ms
95,536 KB
testcase_14 AC 576 ms
95,540 KB
testcase_15 AC 577 ms
95,404 KB
testcase_16 AC 576 ms
95,536 KB
testcase_17 AC 560 ms
95,792 KB
testcase_18 AC 579 ms
95,664 KB
testcase_19 AC 577 ms
95,924 KB
testcase_20 AC 570 ms
95,668 KB
testcase_21 AC 572 ms
95,408 KB
testcase_22 AC 577 ms
95,664 KB
testcase_23 AC 560 ms
95,408 KB
testcase_24 AC 580 ms
95,796 KB
testcase_25 AC 565 ms
95,412 KB
testcase_26 AC 72 ms
73,908 KB
testcase_27 AC 484 ms
91,476 KB
testcase_28 AC 485 ms
91,864 KB
testcase_29 AC 470 ms
91,988 KB
testcase_30 AC 479 ms
91,608 KB
testcase_31 AC 476 ms
91,472 KB
testcase_32 AC 66 ms
71,680 KB
testcase_33 AC 289 ms
84,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import logging
import math
input = sys.stdin.readline
logger = logging.getLogger(__name__)


def read():
    N = int(input().strip())
    AB = []
    for i in range(N):
        a, b = map(int, input().strip().split())
        AB.append((a, b))
    return N, AB


def judge(x, a, b):
    if (x * x - a - b) < 0:
        return False
    left = a * b * 4
    right = (x * x - a - b) * (x * x - a - b)
    return left < right


def solve(N, AB):
    for a, b in AB:
        ok = 10**11
        ng = 2
        while abs(ok - ng) > 1:
            x = (ok + ng) // 2
            if judge(x, a, b):
                ok = x
            else:
                ng = x
        ans = 0
        for x in (ok-1, ok, ok+1):
            if judge(x, a, b):
                ans = x
                break
        if ans == 0:
            raise RuntimeError
        else:
            print(ans)
        


if __name__ == "__main__":
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
0