結果

問題 No.1186 長方形の敷き詰め
ユーザー phsplsphspls
提出日時 2020-09-21 19:04:40
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 1,032 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 145,000 KB
実行使用メモリ 17,644 KB
最終ジャッジ日時 2023-09-06 18:06:43
合計ジャッジ時間 5,258 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 400 ms
17,396 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
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 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 127 ms
6,688 KB
testcase_18 AC 259 ms
12,024 KB
testcase_19 AC 309 ms
13,888 KB
testcase_20 AC 344 ms
15,244 KB
testcase_21 AC 241 ms
11,476 KB
testcase_22 AC 401 ms
17,644 KB
testcase_23 AC 222 ms
10,512 KB
testcase_24 AC 345 ms
15,540 KB
testcase_25 AC 217 ms
10,200 KB
testcase_26 AC 244 ms
11,512 KB
権限があれば一括ダウンロードができます

ソースコード

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 * power(base, p%2) % DIVISOR
}

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 perms: Vec<u64> = vec![1; m as usize + 1usize];
    let mut invs: Vec<u64> = vec![1; m as usize + 1usize];
    for i in 2..=m {
        perms[i as usize] *= perms[i as usize - 1usize] * i % DIVISOR;
        invs[i as usize] = power(perms[i as usize], DIVISOR - 2);
    }
    for i in 0..=m/n {
        let base = (m + i - i * n) as usize;
        let r = min(base - i as usize, i as usize);
        result += perms[base] * invs[base - r] % DIVISOR * invs[r] % DIVISOR;
        result %= DIVISOR;
    }
    println!("{}", result);
}
0