結果
問題 | No.1414 東大文系数学2021第2問改 |
ユーザー | ikd |
提出日時 | 2021-03-01 21:40:24 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 505 ms / 2,000 ms |
コード長 | 3,171 bytes |
コンパイル時間 | 15,863 ms |
コンパイル使用メモリ | 377,868 KB |
実行使用メモリ | 236,416 KB |
最終ジャッジ日時 | 2024-10-03 01:00:41 |
合計ジャッジ時間 | 24,069 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 455 ms
236,288 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 456 ms
236,288 KB |
testcase_05 | AC | 505 ms
236,288 KB |
testcase_06 | AC | 445 ms
236,288 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 455 ms
236,288 KB |
testcase_10 | AC | 499 ms
236,416 KB |
testcase_11 | AC | 452 ms
236,288 KB |
testcase_12 | AC | 461 ms
236,288 KB |
testcase_13 | AC | 461 ms
236,288 KB |
testcase_14 | AC | 503 ms
236,288 KB |
testcase_15 | AC | 467 ms
236,416 KB |
testcase_16 | AC | 457 ms
236,416 KB |
testcase_17 | AC | 463 ms
236,288 KB |
testcase_18 | AC | 465 ms
236,288 KB |
testcase_19 | AC | 496 ms
236,288 KB |
testcase_20 | AC | 494 ms
236,288 KB |
testcase_21 | AC | 452 ms
233,344 KB |
testcase_22 | AC | 1 ms
5,248 KB |
testcase_23 | AC | 465 ms
236,288 KB |
testcase_24 | AC | 457 ms
236,288 KB |
testcase_25 | AC | 461 ms
236,288 KB |
testcase_26 | AC | 458 ms
236,288 KB |
ソースコード
fn main() { let stdin = std::io::stdin(); let mut rd = ProconReader::new(stdin.lock()); let n: usize = rd.get(); let m: usize = rd.get(); let k: usize = rd.get(); let mo = 998244353; let (fac, inv_fac) = factorials(n + 1, mo); let binom = |a: usize, b: usize| { if a < b { 0 } else { fac[a] * inv_fac[b] % mo * inv_fac[a - b] % mo } }; let mut ans = 0; for i in (1..).take_while(|&i| i * k <= m) { let c = binom(n - i * k, n - m) * binom(n - m + 1, i) % mo; if i % 2 == 1 { ans = (ans + c) % mo; } else { ans = (ans + mo - c) % mo; } } println!("{}", ans); } pub fn factorials(size: usize, mo: u64) -> (Vec<u64>, Vec<u64>) { let mut fac = vec![0; size]; let mut inv = vec![0; size]; let mut inv_fac = vec![0; size]; fac[0] = 1; fac[1] = 1; inv[1] = 1; inv_fac[0] = 1; inv_fac[1] = 1; for i in 2..size { let i_u64 = i as u64; fac[i] = fac[i - 1] * i_u64 % mo; inv[i] = ((mo - inv[(mo as usize) % i]) * (mo / i_u64)).rem_euclid(mo); inv_fac[i] = inv_fac[i - 1] * inv[i] % mo; } (fac, inv_fac) } pub struct ProconReader<R> { r: R, l: String, i: usize, } impl<R: std::io::BufRead> ProconReader<R> { pub fn new(reader: R) -> Self { Self { r: reader, l: String::new(), i: 0, } } pub fn get<T>(&mut self) -> T where T: std::str::FromStr, <T as std::str::FromStr>::Err: std::fmt::Debug, { self.skip_blanks(); assert!(self.i < self.l.len()); // remain some character assert_ne!(&self.l[self.i..=self.i], " "); let rest = &self.l[self.i..]; let len = rest.find(' ').unwrap_or_else(|| rest.len()); // parse self.l[self.i..(self.i + len)] let val = rest[..len] .parse() .unwrap_or_else(|e| panic!("{:?}, attempt to read `{}`", e, rest)); self.i += len; val } fn skip_blanks(&mut self) { loop { match self.l[self.i..].find(|ch| ch != ' ') { Some(j) => { self.i += j; break; } None => { let mut buf = String::new(); let num_bytes = self .r .read_line(&mut buf) .unwrap_or_else(|_| panic!("invalid UTF-8")); assert!(num_bytes > 0, "reached EOF :("); self.l = buf .trim_end_matches('\n') .trim_end_matches('\r') .to_string(); self.i = 0; } } } } pub fn get_vec<T>(&mut self, n: usize) -> Vec<T> where T: std::str::FromStr, <T as std::str::FromStr>::Err: std::fmt::Debug, { (0..n).map(|_| self.get()).collect() } pub fn get_chars(&mut self) -> Vec<char> { self.get::<String>().chars().collect() } }