結果
問題 | No.1446 ハンバーグと納豆ごはん |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:20:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 1,690 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 82,472 KB |
実行使用メモリ | 53,856 KB |
最終ジャッジ日時 | 2025-03-20 21:21:51 |
合計ジャッジ時間 | 2,440 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 = 0denominator = N + 1if denominator == 0:return 0 # This case should not happen as N >=1x_opt = (A - B) // denominatorcandidates = [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 = 0else:x = min(x, A // N)if x in seen:continueseen.add(x)a_new = A - x * Nif a_new < 0:continueb_new = B + xcurrent = min(a_new, b_new)if current > best:best = currentreturn bestcurrent_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 = 0denominator = M + 1if denominator == 0:return 0 # This case should not happen as M >=1y_opt = (B - A) // denominatorcandidates = [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 = 0else:y = min(y, B // M)if y in seen:continueseen.add(y)b_new = B - y * Mif b_new < 0:continuea_new = A + ycurrent = min(a_new, b_new)if current > best:best = currentreturn bestcurrent_case3 = compute_case3()if current_case3 > max_t:max_t = current_case3print(max_t)