結果

問題 No.1532 Different Products
ユーザー koba-e964koba-e964
提出日時 2021-10-15 08:39:22
言語 Rust
(1.77.0)
結果
AC  
実行時間 2,151 ms / 4,000 ms
コード長 1,697 bytes
コンパイル時間 1,624 ms
コンパイル使用メモリ 189,724 KB
実行使用メモリ 308,376 KB
最終ジャッジ日時 2023-10-17 19:32:16
合計ジャッジ時間 73,002 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 257 ms
39,628 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 68 ms
20,432 KB
testcase_10 AC 355 ms
78,012 KB
testcase_11 AC 239 ms
39,628 KB
testcase_12 AC 1,014 ms
154,600 KB
testcase_13 AC 411 ms
78,012 KB
testcase_14 AC 1,741 ms
308,272 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 331 ms
78,016 KB
testcase_17 AC 222 ms
39,628 KB
testcase_18 AC 154 ms
39,628 KB
testcase_19 AC 960 ms
154,720 KB
testcase_20 AC 1,875 ms
308,232 KB
testcase_21 AC 454 ms
78,016 KB
testcase_22 AC 498 ms
78,012 KB
testcase_23 AC 208 ms
39,628 KB
testcase_24 AC 1,549 ms
154,720 KB
testcase_25 AC 822 ms
154,716 KB
testcase_26 AC 70 ms
20,436 KB
testcase_27 AC 654 ms
78,020 KB
testcase_28 AC 468 ms
78,016 KB
testcase_29 AC 463 ms
78,020 KB
testcase_30 AC 925 ms
154,720 KB
testcase_31 AC 926 ms
154,720 KB
testcase_32 AC 1,047 ms
154,720 KB
testcase_33 AC 838 ms
154,720 KB
testcase_34 AC 1,315 ms
154,720 KB
testcase_35 AC 1,064 ms
154,720 KB
testcase_36 AC 1,283 ms
154,720 KB
testcase_37 AC 309 ms
78,020 KB
testcase_38 AC 1,395 ms
154,720 KB
testcase_39 AC 1,223 ms
154,720 KB
testcase_40 AC 1,297 ms
154,720 KB
testcase_41 AC 2,117 ms
308,212 KB
testcase_42 AC 1,886 ms
308,212 KB
testcase_43 AC 1,924 ms
308,212 KB
testcase_44 AC 2,086 ms
308,280 KB
testcase_45 AC 2,100 ms
308,348 KB
testcase_46 AC 2,010 ms
308,348 KB
testcase_47 AC 2,064 ms
308,348 KB
testcase_48 AC 2,107 ms
308,348 KB
testcase_49 AC 2,127 ms
308,348 KB
testcase_50 AC 2,146 ms
308,348 KB
testcase_51 AC 2,122 ms
308,348 KB
testcase_52 AC 2,081 ms
308,348 KB
testcase_53 AC 2,140 ms
308,376 KB
testcase_54 AC 2,006 ms
308,220 KB
testcase_55 AC 2,052 ms
308,220 KB
testcase_56 AC 2,151 ms
308,220 KB
testcase_57 AC 2,115 ms
308,220 KB
testcase_58 AC 2,093 ms
308,220 KB
testcase_59 AC 1,935 ms
308,220 KB
testcase_60 AC 2,086 ms
308,220 KB
testcase_61 AC 1 ms
4,348 KB
testcase_62 AC 1 ms
4,348 KB
testcase_63 AC 2,076 ms
308,220 KB
権限があれば一括ダウンロードができます

ソースコード

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

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 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