結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー | phspls |
提出日時 | 2022-11-23 17:23:57 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 894 ms / 2,000 ms |
コード長 | 2,464 bytes |
コンパイル時間 | 12,580 ms |
コンパイル使用メモリ | 392,708 KB |
実行使用メモリ | 316,732 KB |
最終ジャッジ日時 | 2024-09-24 21:03:16 |
合計ジャッジ時間 | 22,888 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 401 ms
114,944 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 894 ms
316,732 KB |
testcase_07 | AC | 400 ms
119,552 KB |
testcase_08 | AC | 738 ms
165,492 KB |
testcase_09 | AC | 887 ms
316,348 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 37 ms
17,280 KB |
testcase_12 | AC | 1 ms
6,944 KB |
testcase_13 | AC | 20 ms
11,700 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 1 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 880 ms
316,356 KB |
testcase_19 | AC | 885 ms
316,408 KB |
testcase_20 | AC | 877 ms
316,344 KB |
testcase_21 | AC | 873 ms
316,424 KB |
testcase_22 | AC | 880 ms
316,368 KB |
testcase_23 | AC | 871 ms
316,400 KB |
testcase_24 | AC | 873 ms
316,360 KB |
ソースコード
use std::collections::HashMap; const MOD: usize = 1e9 as usize + 7; fn fact_inv(size: usize) -> (Vec<usize>, Vec<usize>) { let mut facts = vec![0usize; size+1]; let mut fact_invs = vec![0usize; size+1]; let mut invs = vec![0usize; size+1]; facts[0] = 1; facts[1] = 1; fact_invs[0] = 1; fact_invs[1] = 1; invs[1] = 1; for i in 2..=size { facts[i] = facts[i-1] * i % MOD; invs[i] = MOD - invs[MOD % i] * (MOD / i) % MOD; fact_invs[i] = fact_invs[i - 1] * invs[i] % MOD; } (facts, fact_invs) } fn comb(n: usize, r: usize, facts: &Vec<usize>, fact_invs: &Vec<usize>) -> usize { facts[n] * fact_invs[r] % MOD * fact_invs[n-r] % MOD } fn main() { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<isize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let gx = temp[0]; let gy = temp[1]; let k = temp[2] as usize; let queries = (0..k).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<isize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0], temp[1], temp[2] as usize) }) .collect::<Vec<_>>(); let mut mapping: HashMap<(isize, isize), Vec<Vec<usize>>> = HashMap::new(); mapping.insert((0isize, 0isize), vec![vec![]]); for idx in 0..k { let (ax, ay, n) = queries[idx]; let mut next_map = HashMap::new(); for (&(x, y), v) in mapping.iter() { for vv in v.iter() { for i in 0..=n { let mut nvv = vv.clone().to_owned(); nvv.push(i); let np = (x + i as isize * ax, y + i as isize * ay); next_map.entry(np).or_insert(vec![]).push(nvv); } } } mapping = next_map; } let (facts, fact_invs) = fact_inv(100); let mut result = 0usize; if let Some(v) = mapping.get(&(gx, gy)) { for vv in v.iter() { let mut summary = vv.iter().sum::<usize>(); let mut pat = 1usize; for &val in vv.iter() { pat *= comb(summary, val, &facts, &fact_invs); pat %= MOD; summary -= val; } result += pat; result %= MOD; } } println!("{}", result); }