結果

問題 No.2390 Udon Coupon (Hard)
ユーザー 👑 MizarMizar
提出日時 2023-07-04 03:09:36
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 732 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 50 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 45,800 KB
最終ジャッジ日時 2024-04-15 20:51:48
合計ジャッジ時間 12,798 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
39,040 KB
testcase_01 AC 70 ms
39,424 KB
testcase_02 AC 68 ms
39,680 KB
testcase_03 AC 70 ms
40,448 KB
testcase_04 AC 68 ms
40,320 KB
testcase_05 AC 244 ms
44,900 KB
testcase_06 AC 60 ms
39,040 KB
testcase_07 AC 63 ms
39,168 KB
testcase_08 AC 60 ms
39,040 KB
testcase_09 AC 469 ms
45,544 KB
testcase_10 AC 65 ms
39,552 KB
testcase_11 AC 61 ms
39,040 KB
testcase_12 AC 61 ms
39,168 KB
testcase_13 AC 63 ms
39,168 KB
testcase_14 AC 62 ms
39,168 KB
testcase_15 AC 61 ms
39,168 KB
testcase_16 AC 59 ms
39,168 KB
testcase_17 AC 62 ms
39,424 KB
testcase_18 AC 62 ms
39,424 KB
testcase_19 AC 62 ms
39,552 KB
testcase_20 AC 59 ms
39,424 KB
testcase_21 AC 61 ms
39,168 KB
testcase_22 AC 68 ms
40,704 KB
testcase_23 AC 67 ms
40,576 KB
testcase_24 AC 225 ms
44,904 KB
testcase_25 AC 232 ms
44,904 KB
testcase_26 AC 244 ms
45,028 KB
testcase_27 AC 232 ms
44,904 KB
testcase_28 AC 218 ms
44,904 KB
testcase_29 AC 498 ms
45,416 KB
testcase_30 AC 487 ms
45,800 KB
testcase_31 AC 503 ms
45,540 KB
testcase_32 AC 537 ms
45,540 KB
testcase_33 AC 516 ms
45,796 KB
testcase_34 AC 732 ms
45,796 KB
testcase_35 AC 694 ms
45,544 KB
testcase_36 AC 681 ms
45,676 KB
testcase_37 AC 706 ms
45,544 KB
testcase_38 AC 710 ms
45,544 KB
testcase_39 AC 482 ms
45,032 KB
testcase_40 AC 317 ms
44,908 KB
testcase_41 AC 457 ms
45,036 KB
testcase_42 AC 310 ms
45,032 KB
testcase_43 AC 290 ms
45,032 KB
testcase_44 AC 65 ms
40,320 KB
testcase_45 AC 121 ms
44,900 KB
testcase_46 AC 70 ms
40,960 KB
testcase_47 AC 60 ms
39,552 KB
testcase_48 AC 103 ms
45,032 KB
testcase_49 AC 60 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 r = BigInt(0), a1b2 = a1 * b2, a1b3 = a1 * b3;
for (let p = 0, s = n; p < a1b2 && s >= 0; p += b2, s -= a2) {
	for (let q = 0, t = s; q < a1b3 && t >= 0; q += b3, t -= a3) {
	    // ここの計算は問題の制約上、 Number型ではなく BigInt型 で行わないと精度不足が起きる 
		let u = BigInt(Math.floor(t / a1)) * BigInt(b1) + BigInt(p + q);
		r = (r < u) ? u : r;
	}
}

console.log(r.toString());
0