結果

問題 No.1531 く2
ユーザー koba-e964koba-e964
提出日時 2022-01-03 23:33:05
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,796 bytes
コンパイル時間 1,510 ms
コンパイル使用メモリ 170,368 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 13:42:55
合計ジャッジ時間 2,872 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 1 ms
5,376 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
5,376 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;

#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

const MOD: i64 = 998_244_353;

fn dfs(n: i64, k: i64, memo: &mut HashMap<(i64, i64), i64>) -> i64 {
    if n == 0 {
        let p = k.count_ones();
        return (1i64 << p) % MOD;
    }
    let key = (n, k);
    if let Some(&val) = memo.get(&key) {
        return val;
    }
    let mut ans = dfs(n / 2, k / 2, memo);
    if n % 2 == 1 {
        ans += dfs(n / 2, (k + 1) / 2, memo) * if k % 2 == 1 {
            1
        } else {
            2
        };
        ans %= MOD;
    }
    memo.insert(key, ans);
    ans
}

fn solve() {
    let n: i64 = get();
    let k: i64 = get();
    let mut memo = HashMap::new();
    println!("{}", dfs(n, k, &mut memo));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}
0