結果

問題 No.2390 Udon Coupon (Hard)
ユーザー 👑 MizarMizar
提出日時 2023-07-22 09:44:27
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 721 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 31 ms
コンパイル使用メモリ 5,120 KB
実行使用メモリ 45,676 KB
最終ジャッジ日時 2024-04-15 21:07:39
合計ジャッジ時間 12,875 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
39,424 KB
testcase_01 AC 61 ms
39,424 KB
testcase_02 AC 64 ms
39,680 KB
testcase_03 AC 68 ms
40,576 KB
testcase_04 AC 68 ms
40,192 KB
testcase_05 AC 218 ms
44,900 KB
testcase_06 AC 64 ms
39,040 KB
testcase_07 AC 61 ms
39,168 KB
testcase_08 AC 59 ms
39,040 KB
testcase_09 AC 466 ms
45,540 KB
testcase_10 AC 63 ms
39,808 KB
testcase_11 AC 59 ms
39,168 KB
testcase_12 AC 61 ms
39,424 KB
testcase_13 AC 59 ms
39,168 KB
testcase_14 AC 61 ms
39,168 KB
testcase_15 AC 60 ms
39,040 KB
testcase_16 AC 59 ms
38,912 KB
testcase_17 AC 61 ms
39,424 KB
testcase_18 AC 63 ms
39,296 KB
testcase_19 AC 62 ms
39,040 KB
testcase_20 AC 62 ms
39,168 KB
testcase_21 AC 61 ms
39,424 KB
testcase_22 AC 67 ms
40,448 KB
testcase_23 AC 66 ms
40,704 KB
testcase_24 AC 224 ms
44,904 KB
testcase_25 AC 232 ms
45,032 KB
testcase_26 AC 244 ms
45,156 KB
testcase_27 AC 238 ms
44,900 KB
testcase_28 AC 225 ms
44,904 KB
testcase_29 AC 510 ms
45,540 KB
testcase_30 AC 471 ms
45,676 KB
testcase_31 AC 486 ms
45,668 KB
testcase_32 AC 511 ms
45,540 KB
testcase_33 AC 502 ms
45,544 KB
testcase_34 AC 721 ms
45,672 KB
testcase_35 AC 698 ms
45,416 KB
testcase_36 AC 702 ms
45,544 KB
testcase_37 AC 707 ms
45,540 KB
testcase_38 AC 710 ms
45,544 KB
testcase_39 AC 490 ms
45,032 KB
testcase_40 AC 323 ms
44,900 KB
testcase_41 AC 452 ms
45,156 KB
testcase_42 AC 316 ms
44,908 KB
testcase_43 AC 288 ms
45,156 KB
testcase_44 AC 70 ms
40,064 KB
testcase_45 AC 124 ms
44,776 KB
testcase_46 AC 72 ms
40,960 KB
testcase_47 AC 63 ms
39,424 KB
testcase_48 AC 106 ms
45,032 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 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}`);
0