結果
問題 | No.1688 Veterinarian |
ユーザー | phspls |
提出日時 | 2022-10-18 14:29:31 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 88 ms / 3,000 ms |
コード長 | 2,085 bytes |
コンパイル時間 | 13,874 ms |
コンパイル使用メモリ | 379,296 KB |
実行使用メモリ | 58,880 KB |
最終ジャッジ日時 | 2024-06-28 22:42:25 |
合計ジャッジ時間 | 15,264 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 4 ms
5,376 KB |
testcase_08 | AC | 88 ms
58,880 KB |
testcase_09 | AC | 79 ms
54,528 KB |
testcase_10 | AC | 8 ms
6,656 KB |
testcase_11 | AC | 8 ms
7,424 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 7 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
ソースコード
fn main() { let mut abcn = String::new(); std::io::stdin().read_line(&mut abcn).ok(); let abcn: Vec<usize> = abcn.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let a = abcn[0]; let b = abcn[1]; let c = abcn[2]; let n = abcn[3]; let mut dp = vec![vec![vec![vec![0.; c+1]; b+1]; a+1]; n+1]; dp[0][a][b][c] = 1.; for i in 0..n { for red in 0..=a { for black in 0..=b { for brown in 0..=c { if dp[i][red][black][brown] == 0. { continue; } let summary = red + black + brown; let denom = (summary * (summary-1) / 2) as f64; let mut others = 1.; if red > 1 { dp[i+1][red-1][black][brown] += dp[i][red][black][brown] * (red * (red-1) / 2) as f64 / denom; others -= (red * (red-1) / 2) as f64 / denom; } if black > 1 { dp[i+1][red][black-1][brown] += dp[i][red][black][brown] * (black * (black-1) / 2) as f64 / denom; others -= (black * (black-1) / 2) as f64 / denom; } if brown > 1 { dp[i+1][red][black][brown-1] += dp[i][red][black][brown] * (brown * (brown-1) / 2) as f64 / denom; others -= (brown * (brown-1) / 2) as f64 / denom; } dp[i+1][red][black][brown] += dp[i][red][black][brown] * others; } } } } let mut red_exp = 0.; let mut black_exp = 0.; let mut brown_exp = 0.; for red in 0..=a { for black in 0..=b { for brown in 0..=c { let base = dp[n][red][black][brown]; red_exp += (a - red) as f64 * base; black_exp += (b - black) as f64 * base; brown_exp += (c - brown) as f64 * base; } } } println!("{:.09} {:.09} {:.09}", red_exp, black_exp, brown_exp); }