結果

問題 No.1446 ハンバーグと納豆ごはん
ユーザー kept1994kept1994
提出日時 2022-05-08 02:03:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,169 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 71,528 KB
最終ジャッジ日時 2023-09-21 14:18:45
合計ジャッジ時間 5,459 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,240 KB
testcase_01 AC 72 ms
71,404 KB
testcase_02 AC 72 ms
71,220 KB
testcase_03 AC 77 ms
71,436 KB
testcase_04 AC 73 ms
71,164 KB
testcase_05 AC 71 ms
71,360 KB
testcase_06 AC 71 ms
71,524 KB
testcase_07 AC 71 ms
71,252 KB
testcase_08 AC 73 ms
71,248 KB
testcase_09 AC 73 ms
71,164 KB
testcase_10 AC 71 ms
71,444 KB
testcase_11 AC 73 ms
71,356 KB
testcase_12 AC 74 ms
71,468 KB
testcase_13 AC 75 ms
71,152 KB
testcase_14 AC 75 ms
71,300 KB
testcase_15 AC 75 ms
71,428 KB
testcase_16 AC 74 ms
71,344 KB
testcase_17 AC 75 ms
71,180 KB
testcase_18 AC 74 ms
71,464 KB
testcase_19 AC 75 ms
71,488 KB
testcase_20 AC 74 ms
71,288 KB
testcase_21 AC 75 ms
71,288 KB
testcase_22 AC 74 ms
71,416 KB
testcase_23 AC 75 ms
71,248 KB
testcase_24 AC 79 ms
71,288 KB
testcase_25 AC 74 ms
71,244 KB
testcase_26 AC 73 ms
71,436 KB
testcase_27 AC 75 ms
71,468 KB
testcase_28 AC 74 ms
71,196 KB
testcase_29 AC 73 ms
71,432 KB
testcase_30 AC 73 ms
71,408 KB
testcase_31 AC 73 ms
71,528 KB
testcase_32 AC 73 ms
71,168 KB
testcase_33 AC 73 ms
71,244 KB
testcase_34 AC 72 ms
71,348 KB
testcase_35 AC 74 ms
71,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
MOD = 998244353
input = sys.stdin.readline

def main():
    A, B, N, M = map(int, input().split())
    # False ------ ng | ok ---- True
    def is_ok(k: int):
        if A >= k:
            return B + (A - k) // N >= k
        elif B >= k:
            return A + (B - k) // M >= k
        return False

    def binSearch(ng: int, ok: int):
        # print(ok, ng)              # はじめの2値の状態
        while abs(ok - ng) > 1:     # 終了条件(差が1となり境界を見つけた時)
            mid = (ok + ng) // 2
            # print("target > ", mid)
            result = is_ok(mid)
            # print(result)
            if result:
                ok = mid            # midが条件を満たすならmidまではokなのでokの方を真ん中まで持っていく
            else:
                ng = mid            # midが条件を満たさないならmidまではngなのでngの方を真ん中まで持っていく
            # print(ok, ng)          # 半分に切り分ける毎の2値の状態
        return ok  

    print(binSearch(10 ** 18 + 1, 0))
    return

if __name__ == '__main__':
    main()
0