結果

問題 No.1532 Different Products
ユーザー koba-e964koba-e964
提出日時 2021-10-15 08:41:17
言語 Rust
(1.77.0)
結果
AC  
実行時間 2,202 ms / 4,000 ms
コード長 1,236 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 187,256 KB
実行使用メモリ 309,248 KB
最終ジャッジ日時 2023-10-17 19:33:42
合計ジャッジ時間 70,870 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 250 ms
40,268 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 67 ms
21,268 KB
testcase_10 AC 357 ms
78,844 KB
testcase_11 AC 230 ms
40,264 KB
testcase_12 AC 978 ms
155,548 KB
testcase_13 AC 401 ms
78,844 KB
testcase_14 AC 1,712 ms
309,088 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 333 ms
78,848 KB
testcase_17 AC 227 ms
40,264 KB
testcase_18 AC 168 ms
40,264 KB
testcase_19 AC 984 ms
155,548 KB
testcase_20 AC 1,758 ms
309,088 KB
testcase_21 AC 463 ms
78,852 KB
testcase_22 AC 493 ms
78,844 KB
testcase_23 AC 200 ms
40,264 KB
testcase_24 AC 1,439 ms
155,552 KB
testcase_25 AC 859 ms
155,548 KB
testcase_26 AC 75 ms
21,268 KB
testcase_27 AC 646 ms
78,852 KB
testcase_28 AC 489 ms
78,848 KB
testcase_29 AC 466 ms
78,852 KB
testcase_30 AC 959 ms
155,552 KB
testcase_31 AC 970 ms
155,552 KB
testcase_32 AC 1,093 ms
155,552 KB
testcase_33 AC 849 ms
155,552 KB
testcase_34 AC 1,342 ms
155,552 KB
testcase_35 AC 1,086 ms
155,552 KB
testcase_36 AC 1,265 ms
155,552 KB
testcase_37 AC 309 ms
78,852 KB
testcase_38 AC 1,366 ms
155,552 KB
testcase_39 AC 1,237 ms
155,552 KB
testcase_40 AC 1,279 ms
155,552 KB
testcase_41 AC 2,080 ms
309,088 KB
testcase_42 AC 1,832 ms
309,180 KB
testcase_43 AC 1,939 ms
309,248 KB
testcase_44 AC 2,066 ms
309,052 KB
testcase_45 AC 2,095 ms
309,052 KB
testcase_46 AC 2,048 ms
309,052 KB
testcase_47 AC 2,100 ms
309,120 KB
testcase_48 AC 2,117 ms
309,052 KB
testcase_49 AC 2,097 ms
309,052 KB
testcase_50 AC 2,098 ms
309,052 KB
testcase_51 AC 2,125 ms
309,052 KB
testcase_52 AC 2,082 ms
309,188 KB
testcase_53 AC 2,086 ms
309,188 KB
testcase_54 AC 2,044 ms
309,088 KB
testcase_55 AC 2,097 ms
309,188 KB
testcase_56 AC 2,022 ms
309,088 KB
testcase_57 AC 2,036 ms
309,088 KB
testcase_58 AC 2,083 ms
309,088 KB
testcase_59 AC 1,975 ms
309,088 KB
testcase_60 AC 2,202 ms
309,060 KB
testcase_61 AC 1 ms
4,348 KB
testcase_62 AC 1 ms
4,348 KB
testcase_63 AC 2,130 ms
309,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::*;
use std::io::Read;

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() }

fn dfs(n: i64, k: i64, memo: &mut HashMap<(i64, i64), u64>) -> u64 {
    if let Some(&val) = memo.get(&(n, k)) {
        return val;
    }
    if k <= 0 {
        return 0;
    }
    if n <= 0 {
        return 0;
    }
    let mut sum = if k >= n {
        1
    } else {
        0
    };
    if k >= n {
        sum += dfs(n - 1, k / n, memo);
    }
    sum += dfs(n - 1, k, memo);
    memo.insert((n, k), sum);
    sum
}

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