結果

問題 No.2390 Udon Coupon (Hard)
ユーザー 👑 MizarMizar
提出日時 2023-07-07 16:21:16
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 1,592 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 5,632 KB
実行使用メモリ 178,068 KB
最終ジャッジ日時 2024-04-15 20:54:44
合計ジャッジ時間 20,375 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
39,168 KB
testcase_01 AC 68 ms
39,040 KB
testcase_02 AC 73 ms
39,040 KB
testcase_03 AC 75 ms
39,168 KB
testcase_04 AC 79 ms
39,424 KB
testcase_05 AC 69 ms
38,912 KB
testcase_06 AC 67 ms
38,912 KB
testcase_07 AC 68 ms
39,168 KB
testcase_08 AC 66 ms
38,912 KB
testcase_09 AC 980 ms
114,944 KB
testcase_10 AC 69 ms
39,040 KB
testcase_11 AC 66 ms
38,912 KB
testcase_12 AC 65 ms
38,912 KB
testcase_13 AC 69 ms
39,040 KB
testcase_14 AC 69 ms
39,168 KB
testcase_15 AC 67 ms
39,168 KB
testcase_16 AC 68 ms
39,168 KB
testcase_17 AC 68 ms
39,040 KB
testcase_18 AC 70 ms
39,040 KB
testcase_19 AC 71 ms
38,912 KB
testcase_20 AC 66 ms
39,296 KB
testcase_21 AC 66 ms
39,040 KB
testcase_22 AC 74 ms
39,168 KB
testcase_23 AC 75 ms
39,168 KB
testcase_24 AC 365 ms
54,528 KB
testcase_25 AC 374 ms
55,400 KB
testcase_26 AC 372 ms
55,040 KB
testcase_27 AC 377 ms
55,396 KB
testcase_28 AC 344 ms
53,760 KB
testcase_29 AC 875 ms
104,048 KB
testcase_30 AC 737 ms
88,760 KB
testcase_31 AC 867 ms
103,788 KB
testcase_32 AC 872 ms
103,668 KB
testcase_33 AC 768 ms
91,240 KB
testcase_34 AC 1,589 ms
177,688 KB
testcase_35 AC 1,320 ms
155,592 KB
testcase_36 AC 1,309 ms
153,844 KB
testcase_37 AC 1,592 ms
178,068 KB
testcase_38 AC 1,341 ms
156,064 KB
testcase_39 AC 444 ms
58,852 KB
testcase_40 AC 364 ms
55,128 KB
testcase_41 AC 428 ms
58,112 KB
testcase_42 AC 362 ms
55,296 KB
testcase_43 AC 384 ms
56,168 KB
testcase_44 AC 113 ms
44,032 KB
testcase_45 AC 215 ms
48,512 KB
testcase_46 AC 103 ms
43,516 KB
testcase_47 AC 95 ms
43,392 KB
testcase_48 AC 213 ms
48,256 KB
testcase_49 AC 65 ms
39,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let l = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
let n = parseInt(l[0]);
let [a1, b1] = l[1].split(" ").map(s => parseInt(s));
let [a2, b2] = l[2].split(" ").map(s => parseInt(s));
let [a3, b3] = l[3].split(" ").map(s => parseInt(s));

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];
}
let w = Math.max(Math.floor(n / a1) - a2 - a3, 0);
let m = n - w * a1;
let dp = Array.from({length: m + 1});
dp[0] = 0;
let r = 0;
for (let i = 1; i <= m; i++) {
	dp[i] = r = Math.max(
		i >= a1 ? dp[i - a1] + b1 : 0,
		i >= a2 ? dp[i - a2] + b2 : 0,
		i >= a3 ? dp[i - a3] + b3 : 0,
		r
	);
}
// ここでBigIntを使わないと精度不足になる
console.log(`${BigInt(r) + BigInt(w) * BigInt(b1)}`);
0