結果
問題 | No.895 MESE |
ユーザー | phspls |
提出日時 | 2023-01-19 04:28:46 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,706 bytes |
コンパイル時間 | 15,032 ms |
コンパイル使用メモリ | 396,260 KB |
実行使用メモリ | 8,936 KB |
最終ジャッジ日時 | 2024-06-12 04:29:40 |
合計ジャッジ時間 | 15,150 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 20 ms
6,944 KB |
testcase_14 | AC | 38 ms
6,940 KB |
testcase_15 | AC | 40 ms
6,940 KB |
testcase_16 | AC | 27 ms
6,944 KB |
testcase_17 | AC | 11 ms
6,944 KB |
testcase_18 | AC | 51 ms
8,776 KB |
testcase_19 | AC | 50 ms
8,904 KB |
testcase_20 | AC | 49 ms
8,808 KB |
testcase_21 | AC | 49 ms
8,904 KB |
testcase_22 | AC | 50 ms
8,908 KB |
testcase_23 | AC | 50 ms
8,872 KB |
testcase_24 | AC | 48 ms
8,936 KB |
testcase_25 | AC | 48 ms
8,904 KB |
testcase_26 | AC | 47 ms
8,880 KB |
testcase_27 | AC | 47 ms
8,904 KB |
testcase_28 | AC | 47 ms
8,904 KB |
ソースコード
const MOD: usize = 1e9 as usize + 7; fn power(base: usize, times: usize) -> usize { if times == 0 { return 1usize; } if times == 1 { return base; } let temp = power(base, times/2); temp * temp % MOD * power(base, times%2) % MOD } 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 abc = String::new(); std::io::stdin().read_line(&mut abc).ok(); let abc: Vec<usize> = abc.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let a = abc[0]; let b = abc[1]; let c = abc[2]; let n = a+b+c; let (facts, fact_invs) = fact_inv(n+10); let mut result = 0usize; let mut p2sum = vec![1usize; n]; for i in 1..n { p2sum[i] = p2sum[i-1] * 2 % MOD; } for i in 1..n { p2sum[i] = (p2sum[i] + p2sum[i-1]) % MOD; } for starta in 1..=a { let total_combs = comb(n-starta-1, b-1, &facts, &fact_invs)* comb(n-starta-b, c, &facts, &fact_invs) % MOD; let prob = c * power(n-starta-1, MOD-2) % MOD; result += prob * p2sum[n-starta-2] % MOD * total_combs % MOD; result %= MOD; } println!("{}", result); }