結果

問題 No.2390 Udon Coupon (Hard)
ユーザー 👑 MizarMizar
提出日時 2023-07-07 13:48:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 565 ms / 2,000 ms
コード長 752 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,652 KB
最終ジャッジ日時 2024-10-06 01:39:24
合計ジャッジ時間 25,821 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
n = int(input())
[[a1, b1], [a2, b2], [a3, b3]] = [list(map(int, input().split())) for _ in range(3)]
assert n > 0 and a1 > 0 and a2 > 0 and a3 > 0 and b1 > 0 and b2 > 0 and b3 > 0
assert n < (1 << 64) and n // min(a1, a2, a3) * max(b1, b2, b3) < (1 << 64)
if a2 * b1 < a1 * b2:
	a1, b1, a2, b2 = a2, b2, a1, b1
if a3 * b1 < a1 * b3:
	a1, b1, a3, b3 = a3, b3, a1, b1
w = max(n - (a1 * (a2 + a3)), 0) // a1
r = 0
a1inv = ((1 << 32) - 1) // a1 + 1
for i, j, s in zip(
	range(a1),
	map(lambda s: np.arange(0, min(a1, s // a3 + 1), dtype=np.uint64), range(n - w * a1, -1, -a2)),
	range(n - w * a1, -1, -a2),
):
	t = s - j * a3
	q = t * a1inv >> 32
	q -= (t < q * a1)
	r = max(r, int(np.amax(q * b1 + i * b2 + j * b3)))
print(r + w * b1)
0