結果

問題 No.2390 Udon Coupon (Hard)
ユーザー 👑 MizarMizar
提出日時 2023-07-04 03:22:43
言語 JavaScript
(node v21.7.1)
結果
WA  
実行時間 -
コード長 3,611 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 5,504 KB
実行使用メモリ 43,520 KB
最終ジャッジ日時 2024-07-19 03:15:51
合計ジャッジ時間 5,470 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
40,064 KB
testcase_01 AC 61 ms
40,320 KB
testcase_02 AC 60 ms
40,064 KB
testcase_03 AC 65 ms
40,320 KB
testcase_04 AC 63 ms
40,064 KB
testcase_05 AC 172 ms
43,136 KB
testcase_06 AC 65 ms
40,064 KB
testcase_07 AC 61 ms
40,192 KB
testcase_08 WA -
testcase_09 AC 101 ms
43,264 KB
testcase_10 AC 61 ms
40,192 KB
testcase_11 AC 61 ms
40,192 KB
testcase_12 AC 61 ms
40,064 KB
testcase_13 AC 60 ms
40,064 KB
testcase_14 AC 60 ms
40,064 KB
testcase_15 AC 63 ms
40,192 KB
testcase_16 AC 60 ms
40,320 KB
testcase_17 AC 60 ms
40,064 KB
testcase_18 AC 60 ms
40,192 KB
testcase_19 AC 60 ms
40,064 KB
testcase_20 AC 61 ms
40,064 KB
testcase_21 AC 58 ms
40,064 KB
testcase_22 AC 60 ms
40,320 KB
testcase_23 AC 63 ms
40,448 KB
testcase_24 AC 80 ms
43,392 KB
testcase_25 AC 78 ms
43,520 KB
testcase_26 AC 80 ms
43,392 KB
testcase_27 AC 82 ms
43,392 KB
testcase_28 AC 78 ms
43,264 KB
testcase_29 AC 106 ms
43,136 KB
testcase_30 AC 108 ms
43,392 KB
testcase_31 AC 115 ms
43,264 KB
testcase_32 AC 104 ms
43,264 KB
testcase_33 AC 108 ms
43,264 KB
testcase_34 AC 149 ms
43,136 KB
testcase_35 AC 147 ms
43,264 KB
testcase_36 AC 138 ms
43,520 KB
testcase_37 AC 140 ms
43,264 KB
testcase_38 AC 139 ms
43,264 KB
testcase_39 AC 110 ms
43,264 KB
testcase_40 AC 86 ms
43,264 KB
testcase_41 AC 105 ms
43,264 KB
testcase_42 AC 95 ms
43,392 KB
testcase_43 AC 85 ms
43,264 KB
testcase_44 AC 58 ms
40,192 KB
testcase_45 AC 66 ms
43,392 KB
testcase_46 AC 58 ms
40,064 KB
testcase_47 AC 59 ms
40,064 KB
testcase_48 AC 66 ms
43,264 KB
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

const b64str = 'AGFzbQEAAAABFAJgBX9+fn5+AGAHfn5+fn5+fgF+AwMCAQAFAwEAEQYJAX8BQYCAwAALBxICBm1lbW9yeQIABXNvbHZlAAAKiwQCmQMCA38MfiMAQRBrIgckAAJAIAIgA34gASAEflkEQCAEIQsgAyEKIAIhBCABIQMMAQsgAiELIAEhCgsCQCAEIAV+IAMgBn5ZBEAgBiEOIAUhDSAEIQYgAyEFDAELIAQhDiADIQ0LQgAhAQJAIAVQDQAgBSALfiIRQgFTDQBC//////////8/IAV/IAUgDn4iE0IAVwRAIAshBANAQgAhASAAIAp9IgIgAFMgCkIAVXMNAiAEIBFTIAIhACAEIAt8IQQNAAsMAQtCAXwhEiANQgKGIRQgCkIChiEVIABCAoYhDyAHQQhqIQggDUIAVSEJQgAhAQNAQgAhAiAPIQMgACEEA0ACQCAHIBIgEkI/hyADIANCP4cQASABIAIgEHwgBiAIKQMAIgwgBSAMfiAEVa19fnwiDCABIAxVGyEBIAkgBCANfSIMIARTcw0AIAMgFH0hAyAMIQQgAiAOfCICIBNTDQELCyAAIAp9IgIgAFMgCkIAVXMNASAPIBV9IQ8gAiEAIAsgEHwiECARUw0ACwsgB0EQaiQAIAELbgEGfiAAIANC/////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 {
        let (mut q, mut t) = (0, s);
        while q < a1b3 {
            // 準定数を除数とする除算の定数倍高速化
            // 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);
            if let Some(d) = t.checked_sub(a3) {
                t = d;
                q += b3;
            } else {
                break;
            }
        }
        if let Some(d) = s.checked_sub(a2) {
            s = d;
            p += b2;
        } else {
            break;
        }
    }
    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;
        }
    }
}

*/
0