結果
問題 | No.2390 Udon Coupon (Hard) |
ユーザー | 👑 Mizar |
提出日時 | 2023-08-03 23:03:23 |
言語 | JavaScript (node v21.7.1) |
結果 |
AC
|
実行時間 | 127 ms / 2,000 ms |
コード長 | 3,269 bytes |
コンパイル時間 | 103 ms |
コンパイル使用メモリ | 6,948 KB |
実行使用メモリ | 43,392 KB |
最終ジャッジ日時 | 2024-10-13 20:10:09 |
合計ジャッジ時間 | 6,779 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
40,320 KB |
testcase_01 | AC | 57 ms
40,192 KB |
testcase_02 | AC | 60 ms
40,320 KB |
testcase_03 | AC | 61 ms
40,320 KB |
testcase_04 | AC | 62 ms
40,192 KB |
testcase_05 | AC | 127 ms
43,008 KB |
testcase_06 | AC | 57 ms
40,064 KB |
testcase_07 | AC | 56 ms
40,192 KB |
testcase_08 | AC | 62 ms
40,192 KB |
testcase_09 | AC | 77 ms
43,136 KB |
testcase_10 | AC | 59 ms
40,192 KB |
testcase_11 | AC | 58 ms
40,064 KB |
testcase_12 | AC | 59 ms
40,064 KB |
testcase_13 | AC | 59 ms
40,192 KB |
testcase_14 | AC | 60 ms
40,192 KB |
testcase_15 | AC | 58 ms
40,192 KB |
testcase_16 | AC | 60 ms
40,064 KB |
testcase_17 | AC | 58 ms
40,320 KB |
testcase_18 | AC | 60 ms
40,064 KB |
testcase_19 | AC | 58 ms
40,448 KB |
testcase_20 | AC | 57 ms
40,192 KB |
testcase_21 | AC | 59 ms
40,064 KB |
testcase_22 | AC | 59 ms
40,192 KB |
testcase_23 | AC | 60 ms
40,192 KB |
testcase_24 | AC | 69 ms
43,136 KB |
testcase_25 | AC | 68 ms
43,264 KB |
testcase_26 | AC | 69 ms
43,264 KB |
testcase_27 | AC | 68 ms
43,136 KB |
testcase_28 | AC | 70 ms
43,392 KB |
testcase_29 | AC | 80 ms
43,136 KB |
testcase_30 | AC | 78 ms
43,264 KB |
testcase_31 | AC | 80 ms
43,264 KB |
testcase_32 | AC | 80 ms
43,008 KB |
testcase_33 | AC | 83 ms
43,136 KB |
testcase_34 | AC | 100 ms
43,008 KB |
testcase_35 | AC | 98 ms
43,136 KB |
testcase_36 | AC | 91 ms
43,264 KB |
testcase_37 | AC | 100 ms
43,008 KB |
testcase_38 | AC | 97 ms
43,136 KB |
testcase_39 | AC | 79 ms
43,008 KB |
testcase_40 | AC | 73 ms
43,136 KB |
testcase_41 | AC | 83 ms
43,264 KB |
testcase_42 | AC | 74 ms
43,136 KB |
testcase_43 | AC | 71 ms
43,392 KB |
testcase_44 | AC | 59 ms
40,192 KB |
testcase_45 | AC | 62 ms
43,136 KB |
testcase_46 | AC | 59 ms
40,064 KB |
testcase_47 | AC | 60 ms
40,192 KB |
testcase_48 | AC | 63 ms
43,136 KB |
testcase_49 | AC | 59 ms
40,192 KB |
ソースコード
const b64str = 'AGFzbQEAAAABDAFgB35+fn5+fn4BfgMCAQAFAwEAEQcSAgZtZW1vcnkCAAVzb2x2ZQAACvsCAfgCAgF/Cn4CQCACIAN+IAEgBH5ZBEAgBCEJIAMhCCACIQQgASEDDAELIAIhCSABIQgLAkAgBCAFfiADIAZ+WQRAIAYhCiAFIQIgBCEGIAMhBQwBCyAEIQogAyECCyAFQgFTBEBCAA8LQgAhBCAAIAV/IAIgCHx9IgFCACABQgBVGyENQv////8/IAWAIQMCQCAFIAl+Ig5CAVMNACAAIAUgDX4iAX0iC0IAUw0AIAUgCn4iD0IAVwRAIAAgAX0gCH0hAyAJIQUDQCAFIA5ZDQIgBSAJfCEFIANCf1UgAyAIfSEDDQALDAELIANCAXwhECAAIAF9IAJ9IQxCACEAA0AgDCEBIAshA0IAIQUDQAJAIAQgACAFfCADIBB+QiKHIAZ+fCIRIAQgEVUbIQQgBSAKfCIFIA9ZDQAgAyACfSEDIAFCf1UgASACfSEBDQELCyAAIAl8IgAgDlkNASAMIAh9IQwgCyAIfSILQn9VDQALCyAEIAYgDX58CwBvCXByb2R1Y2VycwIIbGFuZ3VhZ2UBBFJ1c3QADHByb2Nlc3NlZC1ieQMFcnVzdGMdMS43MS4wICg4ZWRlM2FhZTIgMjAyMy0wNy0xMikGd2FscnVzBjAuMTkuMAx3YXNtLWJpbmRnZW4GMC4yLjg3ACwPdGFyZ2V0X2ZlYXR1cmVzAisPbXV0YWJsZS1nbG9iYWxzKwhzaWduLWV4dA=='; 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-pack build --release --target nodejs --no-typescript #[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^34 / a1) = floor((2^34 - 1) / a1) + 1 // 2^32 / a1 <= a1inv < 2^32 / a1 + 1 let a1inv = ((1i64 << 34) - 1) / a1 + 1; let (a1b2, a1b3) = (a1 * b2, a1 * b3); // w = max(floor(n / a1) - (a2 + a3), 0) let w = ((n / a1) - a2 - a3).max(0); let (mut r, mut p, mut s) = (0, 0, n - w * a1); while p < a1b2 && s >= 0 { let (mut q, mut t) = (0, s); while q < a1b3 && t >= 0 { // 準定数を除数とする除算の定数倍高速化 // 0 < {a1,a2,a3} < 2^15, 0 <= t < 2000*(2*2000+1) // a1 * t < 2^34 --> quot = floor(ceil(2^34 / a1) * t / 2^34) = floor(t / a1) let quot = t * a1inv >> 34; debug_assert_eq!(t / a1, quot); r.chmax(quot * b1 + p + q); t -= a3; q += b3; } s -= a2; p += b2; } r + w * b1 } 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; } } } */