結果
| 問題 | No.1186 長方形の敷き詰め |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-20 22:05:43 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,134 bytes |
| 記録 | |
| コンパイル時間 | 553 ms |
| コンパイル使用メモリ | 200,232 KB |
| 実行使用メモリ | 16,064 KB |
| 最終ジャッジ日時 | 2026-03-10 13:38:52 |
| 合計ジャッジ時間 | 10,689 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 4 TLE * 3 |
ソースコード
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);
}