結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
38,912 KB
testcase_01 AC 63 ms
39,296 KB
testcase_02 AC 66 ms
40,320 KB
testcase_03 AC 69 ms
40,832 KB
testcase_04 AC 67 ms
40,832 KB
testcase_05 AC 61 ms
39,296 KB
testcase_06 AC 63 ms
39,040 KB
testcase_07 AC 62 ms
39,168 KB
testcase_08 AC 62 ms
38,912 KB
testcase_09 AC 163 ms
44,544 KB
testcase_10 AC 67 ms
40,064 KB
testcase_11 AC 62 ms
39,168 KB
testcase_12 AC 62 ms
39,168 KB
testcase_13 AC 65 ms
40,192 KB
testcase_14 AC 66 ms
39,936 KB
testcase_15 AC 60 ms
39,296 KB
testcase_16 AC 59 ms
39,424 KB
testcase_17 AC 63 ms
39,680 KB
testcase_18 AC 65 ms
40,192 KB
testcase_19 AC 66 ms
39,936 KB
testcase_20 AC 61 ms
39,040 KB
testcase_21 AC 62 ms
39,040 KB
testcase_22 AC 71 ms
40,960 KB
testcase_23 AC 69 ms
40,960 KB
testcase_24 AC 102 ms
44,800 KB
testcase_25 AC 102 ms
44,928 KB
testcase_26 AC 103 ms
44,672 KB
testcase_27 AC 104 ms
44,544 KB
testcase_28 AC 102 ms
44,800 KB
testcase_29 AC 143 ms
44,672 KB
testcase_30 AC 137 ms
44,928 KB
testcase_31 AC 140 ms
44,672 KB
testcase_32 AC 138 ms
44,800 KB
testcase_33 AC 142 ms
44,928 KB
testcase_34 AC 191 ms
44,672 KB
testcase_35 AC 190 ms
44,544 KB
testcase_36 AC 180 ms
44,800 KB
testcase_37 AC 194 ms
44,800 KB
testcase_38 AC 194 ms
44,928 KB
testcase_39 AC 110 ms
44,800 KB
testcase_40 AC 97 ms
44,800 KB
testcase_41 AC 108 ms
44,544 KB
testcase_42 AC 102 ms
44,672 KB
testcase_43 AC 104 ms
44,800 KB
testcase_44 AC 82 ms
44,544 KB
testcase_45 AC 90 ms
44,672 KB
testcase_46 AC 81 ms
44,672 KB
testcase_47 AC 91 ms
44,800 KB
testcase_48 AC 89 ms
44,928 KB
testcase_49 AC 61 ms
39,168 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: 2048}, e => -Infinity);
let r = 0;
for (let i = 0; i <= m; i++) {
	dp[i & 2047] = r = Math.max(
		dp[(i - a1) & 2047] + b1,
		dp[(i - a2) & 2047] + b2,
		dp[(i - a3) & 2047] + b3,
		r
	);
}
// ここでBigIntを使わないと精度不足になる
console.log(`${BigInt(r) + BigInt(w) * BigInt(b1)}`);
0