結果

問題 No.2390 Udon Coupon (Hard)
ユーザー 👑 MizarMizar
提出日時 2023-07-07 19:32:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 893 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 160,580 KB
最終ジャッジ日時 2023-09-29 13:10:34
合計ジャッジ時間 5,088 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,796 KB
testcase_01 AC 17 ms
8,208 KB
testcase_02 AC 27 ms
8,560 KB
testcase_03 AC 36 ms
8,740 KB
testcase_04 AC 33 ms
8,800 KB
testcase_05 AC 18 ms
8,212 KB
testcase_06 AC 16 ms
7,800 KB
testcase_07 AC 16 ms
7,784 KB
testcase_08 AC 16 ms
7,936 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
[[a1, b1], [a2, b2], [a3, b3]] = [list(map(int, input().split())) for _ in range(3)]
amin, bmin = min(a1, a2, a3), min(b1, b2, b3)
assert n > 0 and amin > 0 and bmin > 0
# 割引額/使用枚数 が 最大効率な組み合わせを(a1,b1)になるように入れ替え
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: 確定で(a1,b1)の割引を使う回数
w = max(n // a1 - a2 - a3, 0)
# m: DPで調べる「うどん札」の残り枚数
m = min(a1 * (a2 + a3) + (n % a1), n)
assert n == w * a1 + m
# DP(動的計画法)
dp = [0] * (m + 1)
r = 0
for i in range(m + 1):
	dp[i] = r = max(
		dp[i - a1] + b1 if i >= a1 else 0,
		dp[i - a2] + b2 if i >= a2 else 0,
		dp[i - a3] + b3 if i >= a3 else 0,
		r,
	)
# 確定で(a1,b1)の割引を使った回数分の割引額(w * b1)を加える
print(r + w * b1)
0