結果

問題 No.1186 長方形の敷き詰め
ユーザー phsplsphspls
提出日時 2020-09-20 22:05:43
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,134 bytes
コンパイル時間 727 ms
コンパイル使用メモリ 148,772 KB
実行使用メモリ 6,772 KB
最終ジャッジ日時 2023-09-06 16:34:49
合計ジャッジ時間 5,227 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::min;

const DIVISOR: u64 = 998244353;

fn power(base: u64, p: u64) -> u64 {
    if p == 0 { return 1; }
    if p == 1 { return base; }
    let temp = power(base, p/2);
    temp * temp % DIVISOR * base % DIVISOR
}

fn comb(n: u64, r: u64, memo: &mut Vec<Option<u64>>) -> u64 {
    if r == 0 || r == n { return 1u64; }
    let mut result = 1u64;
    for i in 1..=r {
        result *= n + 1 - i;
        result %= DIVISOR;
        if memo[r as usize].is_none() {
            memo[r as usize] = Some(power(r, DIVISOR - 2));
        }
        result *= memo[r as usize].unwrap();
        result %= DIVISOR;
    }
    result
}

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<u64> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];

    let mut result: u64 = 0;
    let mut memo: Vec<Option<u64>> = vec![None; m as usize + 1usize];
    for i in 0..=m/n {
        let base = m + i - i * n;
        result += comb(base, min(base - i, i), &mut memo);
        result %= DIVISOR;
    }
    println!("{}", result);
}
0