結果
問題 | No.2390 Udon Coupon (Hard) |
ユーザー | 👑 Mizar |
提出日時 | 2023-07-03 15:51:51 |
言語 | JavaScript (node v21.7.1) |
結果 |
AC
|
実行時間 | 322 ms / 2,000 ms |
コード長 | 4,038 bytes |
コンパイル時間 | 79 ms |
コンパイル使用メモリ | 6,692 KB |
実行使用メモリ | 43,624 KB |
最終ジャッジ日時 | 2024-10-06 01:33:07 |
合計ジャッジ時間 | 8,313 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
40,192 KB |
testcase_01 | AC | 53 ms
40,320 KB |
testcase_02 | AC | 56 ms
40,192 KB |
testcase_03 | AC | 56 ms
40,192 KB |
testcase_04 | AC | 57 ms
40,192 KB |
testcase_05 | AC | 141 ms
43,520 KB |
testcase_06 | AC | 57 ms
40,192 KB |
testcase_07 | AC | 56 ms
40,320 KB |
testcase_08 | AC | 60 ms
40,320 KB |
testcase_09 | AC | 247 ms
43,372 KB |
testcase_10 | AC | 56 ms
40,192 KB |
testcase_11 | AC | 54 ms
40,192 KB |
testcase_12 | AC | 55 ms
40,192 KB |
testcase_13 | AC | 56 ms
40,192 KB |
testcase_14 | AC | 56 ms
40,192 KB |
testcase_15 | AC | 56 ms
40,320 KB |
testcase_16 | AC | 57 ms
40,064 KB |
testcase_17 | AC | 56 ms
40,448 KB |
testcase_18 | AC | 58 ms
40,320 KB |
testcase_19 | AC | 64 ms
40,320 KB |
testcase_20 | AC | 62 ms
40,320 KB |
testcase_21 | AC | 63 ms
40,192 KB |
testcase_22 | AC | 60 ms
40,064 KB |
testcase_23 | AC | 58 ms
40,192 KB |
testcase_24 | AC | 113 ms
43,364 KB |
testcase_25 | AC | 117 ms
43,496 KB |
testcase_26 | AC | 113 ms
43,364 KB |
testcase_27 | AC | 114 ms
43,368 KB |
testcase_28 | AC | 106 ms
43,364 KB |
testcase_29 | AC | 195 ms
43,368 KB |
testcase_30 | AC | 174 ms
43,496 KB |
testcase_31 | AC | 193 ms
43,620 KB |
testcase_32 | AC | 190 ms
43,372 KB |
testcase_33 | AC | 185 ms
43,492 KB |
testcase_34 | AC | 322 ms
43,368 KB |
testcase_35 | AC | 287 ms
43,492 KB |
testcase_36 | AC | 288 ms
43,368 KB |
testcase_37 | AC | 305 ms
43,368 KB |
testcase_38 | AC | 300 ms
43,372 KB |
testcase_39 | AC | 132 ms
43,620 KB |
testcase_40 | AC | 113 ms
43,240 KB |
testcase_41 | AC | 132 ms
43,368 KB |
testcase_42 | AC | 112 ms
43,496 KB |
testcase_43 | AC | 127 ms
43,368 KB |
testcase_44 | AC | 112 ms
43,496 KB |
testcase_45 | AC | 99 ms
43,368 KB |
testcase_46 | AC | 81 ms
43,372 KB |
testcase_47 | AC | 88 ms
43,620 KB |
testcase_48 | AC | 117 ms
43,624 KB |
testcase_49 | AC | 55 ms
40,320 KB |
ソースコード
const b64str = 'AGFzbQEAAAABFAJgBX9+fn5+AGAHfn5+fn5+fgF+AwMCAQAFAwEAEQYJAX8BQYCAwAALBxICBm1lbW9yeQIABXNvbHZlAAAKgAgCjgcCAn8PfiMAQTBrIggkAAJAIAFQDQAgAEIAUw0AIAEgBH4iEkIBUw0AQv//////////PyABfyABIAZ+IhRCAFcEQCAAIAN9IQogBCEJA0AgCSASWQ0CIAQgCXwhCSAKQn9VIAogA30hCg0ACwwBC0IBfCETIAVCAoYhFSADQgKGIRYgAEIChiEOQgAgBX0hFyAIQShqIQcgACEPA0BCACEMIA4hCSAPIQoDQAJAIAhBIGogEyATQj+HIAkgCUI/hxABIBEgDCANfCACIAcpAwAiCyABIAt+IApVrX1+fCILIBEgC1UbIREgBiAMfCIMIBRZDQAgCiAXfCAJIBV9IQkgCiAFfSEKQn9VDQELCyAEIA18Ig0gElkNASAOIBZ9IQ4gDyADfSIPQn9VDQALCwJAIANQDQAgAEIAUw0AIAMgBn4iEkIBUw0AQv//////////PyADf0IAIQ0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XMCKw9tdXRhYmxlLWdsb2JhbHMrCHNpZ24tZXh0'; 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, a1: i64, b1: i64, a2: i64, b2: i64, a3: i64, b3: i64) -> i64 { co_solve(n as i64, [(a1, b1), (a2, b2), (a3, b3)]) .max(co_solve(n as i64, [(a2, b2), (a3, b3), (a1, b1)])) .max(co_solve(n as i64, [(a3, b3), (a1, b1), (a2, b2)])) } fn co_solve(n: i64, ab: [(i64, i64); 3]) -> i64 { let [(ap, bp), (aq, bq), (ar, br)] = ab; if ap == 0 { return 0; } // a_p_inv = ceil(2^62 / a_p) = floor((2^62 - 1) / a_p) + 1 let apinv = ((1i64 << 62) - 1) / ap + 1; let (imax, jmax) = (ap * bq, ap * br); let (mut r, mut i, mut di) = (0, 0, n); while i < imax && di >= 0 { let (mut j, mut dj) = (0, di); while j < jmax && dj >= 0 { // 準定数を除数とする除算の定数倍高速化 // 0 < a_p <= 10^5, 0 <= d_j <= n <= 10^13 < 2^62/10^5 <= 2^62 / a_p <= ceil(2^62 / a_p) = a_p_inv < ((2^62 / a_p) + 1) // quot = floor((n - (i * a_q + j * a_r)) / a_p) = floor(d / a_p) = floor((d * 4) * ceil(2^62 / a_p) / 2^64) - (0 または 1) let qsim = ((((dj * 4) as u128) * (apinv as u128)) >> 64) as i64; let quot = qsim - i64::from(qsim * ap > dj); r.chmax(quot * bp + i + j); dj -= ar; j += br; } di -= aq; i += bq; } r } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } */