結果
問題 | No.1688 Veterinarian |
ユーザー | koba-e964 |
提出日時 | 2021-09-24 22:11:33 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 147 ms / 3,000 ms |
コード長 | 3,161 bytes |
コンパイル時間 | 14,132 ms |
コンパイル使用メモリ | 377,444 KB |
実行使用メモリ | 59,136 KB |
最終ジャッジ日時 | 2024-07-05 10:42:27 |
合計ジャッジ時間 | 15,380 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 7 ms
5,376 KB |
testcase_08 | AC | 147 ms
59,136 KB |
testcase_09 | AC | 134 ms
54,784 KB |
testcase_10 | AC | 13 ms
6,912 KB |
testcase_11 | AC | 14 ms
7,680 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | AC | 8 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::*; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($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_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_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:tt ]) => {{ let len = read_value!($next, usize); read_value!($next, [$t; len]) }}; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); } fn solve() { input!(a: usize, b: usize, c: usize, n: usize); let mut dp = vec![vec![vec![vec![0.0; c + 1]; b + 1]; a + 1]; n + 1]; dp[0][a][b][c] = 1.0; for i in 0..n { for j in 1..a + 1 { for k in 1..b + 1 { for l in 1..c + 1 { let x = (j + k + l) as f64; let me = dp[i][j][k][l]; let whole = x * (x - 1.0); let mut rem = whole; dp[i + 1][j - 1][k][l] += me * (j * (j - 1)) as f64 / whole; dp[i + 1][j][k - 1][l] += me * (k * (k - 1)) as f64 / whole; dp[i + 1][j][k][l - 1] += me * (l * (l - 1)) as f64 / whole; rem -= (j * (j - 1)) as f64; rem -= (k * (k - 1)) as f64; rem -= (l * (l - 1)) as f64; dp[i + 1][j][k][l] += me * rem / whole; } } } } let mut ans = [0.0; 3]; for j in 0..a + 1 { for k in 0..b + 1 { for l in 0..c + 1 { let p = dp[n][j][k][l]; ans[0] += (a - j) as f64 * p; ans[1] += (b - k) as f64 * p; ans[2] += (c - l) as f64 * p; } } } println!("{} {} {}", ans[0], ans[1], ans[2]); }