結果
問題 | No.2390 Udon Coupon (Hard) |
ユーザー | 👑 Mizar |
提出日時 | 2023-07-04 03:25:51 |
言語 | JavaScript (node v21.7.1) |
結果 |
AC
|
実行時間 | 139 ms / 2,000 ms |
コード長 | 3,401 bytes |
コンパイル時間 | 236 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 43,520 KB |
最終ジャッジ日時 | 2024-10-06 01:37:22 |
合計ジャッジ時間 | 5,274 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
39,552 KB |
testcase_01 | AC | 57 ms
40,448 KB |
testcase_02 | AC | 57 ms
39,296 KB |
testcase_03 | AC | 58 ms
40,320 KB |
testcase_04 | AC | 57 ms
39,424 KB |
testcase_05 | AC | 77 ms
42,624 KB |
testcase_06 | AC | 55 ms
40,448 KB |
testcase_07 | AC | 56 ms
39,424 KB |
testcase_08 | AC | 56 ms
40,448 KB |
testcase_09 | AC | 99 ms
43,520 KB |
testcase_10 | AC | 57 ms
39,424 KB |
testcase_11 | AC | 55 ms
39,552 KB |
testcase_12 | AC | 56 ms
40,192 KB |
testcase_13 | AC | 55 ms
39,424 KB |
testcase_14 | AC | 59 ms
39,680 KB |
testcase_15 | AC | 56 ms
39,808 KB |
testcase_16 | AC | 57 ms
39,552 KB |
testcase_17 | AC | 58 ms
40,192 KB |
testcase_18 | AC | 57 ms
39,552 KB |
testcase_19 | AC | 56 ms
39,680 KB |
testcase_20 | AC | 55 ms
39,424 KB |
testcase_21 | AC | 56 ms
39,808 KB |
testcase_22 | AC | 56 ms
39,424 KB |
testcase_23 | AC | 55 ms
39,680 KB |
testcase_24 | AC | 74 ms
42,624 KB |
testcase_25 | AC | 77 ms
43,264 KB |
testcase_26 | AC | 73 ms
42,624 KB |
testcase_27 | AC | 75 ms
43,392 KB |
testcase_28 | AC | 74 ms
42,496 KB |
testcase_29 | AC | 97 ms
42,624 KB |
testcase_30 | AC | 95 ms
42,496 KB |
testcase_31 | AC | 95 ms
42,496 KB |
testcase_32 | AC | 102 ms
42,496 KB |
testcase_33 | AC | 104 ms
42,624 KB |
testcase_34 | AC | 133 ms
42,496 KB |
testcase_35 | AC | 129 ms
42,624 KB |
testcase_36 | AC | 134 ms
42,496 KB |
testcase_37 | AC | 139 ms
42,752 KB |
testcase_38 | AC | 132 ms
42,368 KB |
testcase_39 | AC | 97 ms
42,752 KB |
testcase_40 | AC | 81 ms
42,496 KB |
testcase_41 | AC | 93 ms
42,624 KB |
testcase_42 | AC | 81 ms
42,496 KB |
testcase_43 | AC | 79 ms
42,496 KB |
testcase_44 | AC | 57 ms
39,424 KB |
testcase_45 | AC | 62 ms
42,496 KB |
testcase_46 | AC | 56 ms
39,296 KB |
testcase_47 | AC | 55 ms
39,424 KB |
testcase_48 | AC | 68 ms
43,520 KB |
testcase_49 | AC | 55 ms
39,552 KB |
ソースコード
const b64str = 'AGFzbQEAAAABFAJgBX9+fn5+AGAHfn5+fn5+fgF+AwMCAQAFAwEAEQYJAX8BQYCAwAALBxICBm1lbW9yeQIABXNvbHZlAAAK/AMCigMCAn8NfiMAQRBrIgckAAJAIAIgA34gASAEflkEQCAEIQkgAyEKIAIhBCABIQMMAQsgAiEJIAEhCgsCQCAEIAV+IAMgBn5ZBEAgBiENIAUhDCAEIQYgAyEFDAELIAQhDSADIQwLQgAhAgJAIAVQIABCAFNyDQAgBSAJfiIQQgFTDQBC//////////8/IAV/IAUgDX4iEkIAVwRAIAAgCn0hAyAJIQQDQCAEIBBZDQIgBCAJfCEEIANCf1UgAyAKfSEDDQALDAELQgF8IREgDEIChiETIApCAoYhFCAAQgKGIQ5CACAMfSEVIAdBCGohCANAQgAhASAOIQQgACEDA0ACQCAHIBEgEUI/hyAEIARCP4cQASACIAEgD3wgBiAIKQMAIgsgBSALfiADVa19fnwiCyACIAtVGyECIAEgDXwiASASWQ0AIAMgFXwgBCATfSEEIAMgDH0hA0J/VQ0BCwsgCSAPfCIPIBBZDQEgDiAUfSEOIAAgCn0iAEJ/VQ0ACwsgB0EQaiQAIAILbgEGfiAAIANC/////w+DIgUgAUL/////D4MiBn4iByAFIAFCIIgiCH4iCSAGIANCIIgiBn58IgVCIIZ8Igo3AwAgACAKIAdUrSAGIAh+IAUgCVStQiCGIAVCIIiEfHwgASAEfiACIAN+fHw3AwgLAG8JcHJvZHVjZXJzAghsYW5ndWFnZQEEUnVzdAAMcHJvY2Vzc2VkLWJ5AwVydXN0Yx0xLjcwLjAgKDkwYzU0MTgwNiAyMDIzLTA1LTMxKQZ3YWxydXMGMC4xOS4wDHdhc20tYmluZGdlbgYwLjIuODcALA90YXJnZXRfZmVhdHVyZXMCKw9tdXRhYmxlLWdsb2JhbHMrCHNpZ24tZXh0'; let imports = {}; let wasm; //const bytes = Buffer.from(b64str, 'base64'); const bytes = Uint8Array.from([...atob(b64str)].map(s=>s.charCodeAt(0))); const wasmModule = new WebAssembly.Module(bytes); const wasmInstance = new WebAssembly.Instance(wasmModule, imports); wasm = wasmInstance.exports; let l = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"); let n = BigInt(l[0]); let [a1, b1] = l[1].split(" ").map(s => BigInt(s)); let [a2, b2] = l[2].split(" ").map(s => BigInt(s)); let [a3, b3] = l[3].split(" ").map(s => BigInt(s)); console.log(wasm.solve(n,a1,b1,a2,b2,a3,b3).toString()); /* // WebAssembly Source Code (Rust): use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn solve( n: i64, mut a1: i64, mut b1: i64, mut a2: i64, mut b2: i64, mut a3: i64, mut b3: i64, ) -> i64 { if a2 * b1 < a1 * b2 { std::mem::swap(&mut a1, &mut a2); std::mem::swap(&mut b1, &mut b2); } if a3 * b1 < a1 * b3 { std::mem::swap(&mut a1, &mut a3); std::mem::swap(&mut b1, &mut b3); } if a1 == 0 { return 0; } // a1inv = ceil(2^62 / a1) = floor((2^62 - 1) / a1) + 1 let a1inv = ((1i64 << 62) - 1) / a1 + 1; let (a1b2, a1b3) = (a1 * b2, a1 * b3); let (mut r, mut p, mut s) = (0, 0, n); while p < a1b2 && s >= 0 { let (mut q, mut t) = (0, s); while q < a1b3 && t >= 0 { // 準定数を除数とする除算の定数倍高速化 // 0 < a1 <= 10^5, 0 <= t <= n <= 10^13 < 2^62/10^5 <= 2^62 / a1 <= ceil(2^62 / a1) = a1inv < ((2^62 / a1) + 1) // quot = floor((n - (i * a2 + j * a3)) / a1) = floor(t / a1) = floor((t * 4) * ceil(2^62 / a1) / 2^64) - (0 または 1) let qsim = ((((t * 4) as u128) * (a1inv as u128)) >> 64) as i64; let quot = qsim - i64::from(qsim * a1 > t); debug_assert_eq!(t / a1, quot); r.chmax(quot * b1 + p + q); t -= a3; q += b3; } s -= a2; p += b2; } r } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { #[inline] fn chmax(&mut self, x: T) { if *self < x { *self = x; } } #[inline] fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } */