結果
| 問題 | No.1186 長方形の敷き詰め |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-20 22:05:43 |
| 言語 | Rust (1.92.0 + proconio + num) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,134 bytes |
| 記録 | |
| コンパイル時間 | 13,401 ms |
| コンパイル使用メモリ | 385,160 KB |
| 実行使用メモリ | 13,760 KB |
| 最終ジャッジ日時 | 2024-06-24 11:00:28 |
| 合計ジャッジ時間 | 17,766 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 WA * 3 TLE * 1 -- * 17 |
ソースコード
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);
}