結果
問題 | No.2527 H and W |
ユーザー | ikoma |
提出日時 | 2023-11-03 23:34:43 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,739 bytes |
コンパイル時間 | 13,894 ms |
コンパイル使用メモリ | 378,324 KB |
実行使用メモリ | 17,660 KB |
最終ジャッジ日時 | 2024-09-25 21:33:44 |
合計ジャッジ時間 | 12,809 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 20 ms
17,508 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 25 ms
17,536 KB |
testcase_06 | AC | 24 ms
17,460 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 19 ms
17,536 KB |
testcase_09 | AC | 15 ms
17,536 KB |
testcase_10 | AC | 14 ms
17,536 KB |
testcase_11 | AC | 24 ms
17,660 KB |
testcase_12 | AC | 25 ms
17,524 KB |
testcase_13 | AC | 24 ms
17,536 KB |
testcase_14 | AC | 25 ms
17,536 KB |
testcase_15 | AC | 32 ms
17,536 KB |
testcase_16 | AC | 18 ms
17,536 KB |
testcase_17 | AC | 17 ms
17,536 KB |
testcase_18 | AC | 18 ms
17,600 KB |
testcase_19 | AC | 11 ms
11,228 KB |
testcase_20 | AC | 13 ms
12,672 KB |
testcase_21 | AC | 18 ms
17,448 KB |
testcase_22 | AC | 18 ms
17,512 KB |
testcase_23 | AC | 17 ms
17,560 KB |
testcase_24 | AC | 12 ms
11,948 KB |
testcase_25 | AC | 12 ms
15,232 KB |
ソースコード
#![allow(unused_imports, dead_code, unused_macros, unused_variables, non_snake_case, unused_parens)] use std::cmp::{min,max,Ordering,Reverse}; use std::mem::swap; use std::collections::{VecDeque,LinkedList,HashMap,BTreeMap,HashSet,BTreeSet,BinaryHeap}; fn solve() { input! { h: usize, w: usize, k: usize, } let cmb = ModCombination::new(h.max(w)); let mut ans = 0; for i in 1..h { if k % i != 0 {continue} let j = k / i; if j == w{continue} ans = (ans + cmb.nCr(h, i) * cmb.nCr(w, j)) % MOD; } if k % w == 0 { let x = k / w; ans = (ans + cmb.nCr(h, x)) % MOD; } if k % h == 0 { let x = k / h; ans = (ans + cmb.nCr(w, x)) % MOD; } println!("{}", ans); } fn main() { std::thread::Builder::new() .stack_size(128 * 1024 * 1024) .spawn(|| solve()).unwrap() .join().unwrap(); } type Int = i64; const MOD:Int = 998244353; const fn pow_mod(x: Int, mut n: Int, m: Int) -> Int { if m == 1 { return 0; } let mut r: u64 = 1; let mut y: u64 = x.rem_euclid(m) as u64; while n != 0 { if (n & 1) > 0 { r = (r * y) % (m as u64); } y = (y * y) % (m as u64); n >>= 1; } r as Int } pub struct ModCombination { fac: Vec<Int>, ifac: Vec<Int>, } impl ModCombination { pub fn new(size:usize) -> Self { let mut fac = vec![1; size+1]; let mut f = 1; let mut i = 2; while i <= size { f = f * i as Int % MOD; fac[i] = f; i+=1; } let mut ifac = vec![1; size+1]; let mut f = pow_mod(fac[size], MOD-2, MOD); ifac[size] = f; let mut i = size; while i > 0 { f = f * i as Int % MOD; i-=1; ifac[i] = f; } Self {fac, ifac} } #[inline] pub fn nCr(&self, n:usize, r:usize) -> Int { if n < r { return 0; } self.fac[n] * self.ifac[r] % MOD * self.ifac[n-r] % MOD } #[inline] pub fn nPr(&self, n:usize, r:usize) -> Int { if n < r { return 0; } self.fac[n] * self.ifac[n-r] % MOD } #[inline] pub fn nHr(&self, n:usize, r:usize) -> Int { if n==0 && r==0 {return 1;} self.nCr(n+r-1, r) } } mod _input { // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } #[macro_export] macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } }