結果
| 問題 | No.1446 ハンバーグと納豆ごはん | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-03-20 18:55:02 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 38 ms / 2,000 ms | 
| コード長 | 1,690 bytes | 
| コンパイル時間 | 200 ms | 
| コンパイル使用メモリ | 82,712 KB | 
| 実行使用メモリ | 54,216 KB | 
| 最終ジャッジ日時 | 2025-03-20 18:56:58 | 
| 合計ジャッジ時間 | 2,776 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 33 | 
ソースコード
A, B, N, M = map(int, input().split())
max_t = min(A, B)
# Function to compute best T when converting hamburgers (case 2: y=0)
def compute_case2():
    best = 0
    denominator = N + 1
    if denominator == 0:
        return 0  # This case should not happen as N >=1
    x_opt = (A - B) // denominator
    candidates = [x_opt - 2, x_opt -1, x_opt, x_opt +1, x_opt +2, 0, A//N]
    seen = set()
    for x in candidates:
        x = max(0, x)
        if N == 0:
            x = 0
        else:
            x = min(x, A // N)
        if x in seen:
            continue
        seen.add(x)
        a_new = A - x * N
        if a_new < 0:
            continue
        b_new = B + x
        current = min(a_new, b_new)
        if current > best:
            best = current
    return best
current_case2 = compute_case2()
if current_case2 > max_t:
    max_t = current_case2
# Function to compute best T when converting natto (case 3: x=0)
def compute_case3():
    best = 0
    denominator = M + 1
    if denominator == 0:
        return 0  # This case should not happen as M >=1
    y_opt = (B - A) // denominator
    candidates = [y_opt - 2, y_opt -1, y_opt, y_opt +1, y_opt +2, 0, B//M]
    seen = set()
    for y in candidates:
        y = max(0, y)
        if M == 0:
            y = 0
        else:
            y = min(y, B // M)
        if y in seen:
            continue
        seen.add(y)
        b_new = B - y * M
        if b_new < 0:
            continue
        a_new = A + y
        current = min(a_new, b_new)
        if current > best:
            best = current
    return best
current_case3 = compute_case3()
if current_case3 > max_t:
    max_t = current_case3
print(max_t)
            
            
            
        