結果
問題 | No.309 シャイな人たち (1) |
ユーザー | koba-e964 |
提出日時 | 2021-11-22 18:28:22 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 2,508 ms / 4,000 ms |
コード長 | 4,645 bytes |
コンパイル時間 | 17,176 ms |
コンパイル使用メモリ | 390,136 KB |
実行使用メモリ | 34,944 KB |
最終ジャッジ日時 | 2024-06-24 06:32:30 |
合計ジャッジ時間 | 43,087 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,343 ms
34,944 KB |
testcase_01 | AC | 2,508 ms
34,944 KB |
testcase_02 | AC | 2,207 ms
34,944 KB |
testcase_03 | AC | 2,359 ms
34,944 KB |
testcase_04 | AC | 31 ms
6,940 KB |
testcase_05 | AC | 536 ms
10,240 KB |
testcase_06 | AC | 2,201 ms
34,944 KB |
testcase_07 | AC | 2,217 ms
34,816 KB |
testcase_08 | AC | 2,363 ms
34,944 KB |
testcase_09 | AC | 2,373 ms
34,816 KB |
testcase_10 | AC | 2,409 ms
34,944 KB |
testcase_11 | AC | 2,421 ms
34,944 KB |
testcase_12 | AC | 2,382 ms
34,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 497 ms
10,240 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 ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } /// Generates an Iterator over subsets of univ, in the descending order. /// Verified by: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3050308 struct SubsetIter { bits: Option<usize>, univ: usize } impl Iterator for SubsetIter { type Item = usize; fn next(&mut self) -> Option<usize> { match self.bits { None => None, Some(bits) => { let ans = bits; self.bits = if bits == 0 { None } else { Some((bits - 1) & self.univ) }; Some(ans) } } } } fn subsets(univ: usize) -> SubsetIter { SubsetIter { bits: Some(univ), univ: univ } } fn find(c: usize, one: usize, two: usize, three: usize) -> usize { let mut vis = (1 << c) - one - two - three - 1; loop { let nv = vis | ((vis << 1 | vis >> 1) & one); if nv == vis { break; } vis = nv; } let mut added = 0; for i in 0..c { if (two & 1 << i) != 0 && ((vis << 1) & (5 << i)) == 5 << i { added |= 1 << i; } } vis | added } fn main() { input! { r: usize, c: usize, p: [[f64; c]; r], s: [[i32; c]; r], } let mut memo = vec![vec![0; 1 << c]; 1 << c]; for i in 0..1 << c { for j in 0..1 << c { let mut rem = vec![0; c]; for k in 0..c { if (i & 1 << k) != 0 { rem[k] |= 1; } if (j & 1 << k) != 0 { rem[k] |= 2; } memo[i][j] = find(c, i & !j, !i & j, i & j); } } } let mut dp = vec![0.0; 1 << c]; let mut dpx = vec![0.0; 1 << c]; dp[0] = 1.0; for i in 0..r { let mut ep = vec![0.0; 1 << c]; let mut epx = vec![0.0; 1 << c]; for bits in 0..1 << c { let mut rem = vec![4; c]; let mut pr = 1.0; for j in 0..c { if (bits & 1 << j) != 0 { rem[j] = s[i][j]; pr *= p[i][j] / 100.0; } else { pr *= 1.0 - p[i][j] / 100.0; } } let mut sum = vec![0.0; 1 << c]; let mut sumx = vec![0.0; 1 << c]; for pre in 0..1 << c { let to = pre & bits; sum[to] += dp[pre]; sumx[to] += dpx[pre]; } for pre in subsets(bits) { let sum = sum[pre]; let sumx = sumx[pre]; if sum == 0.0 { continue; } for j in 0..c { if (pre & 1 << j) != 0 { rem[j] -= 1; } } let mut one = 0; let mut two = 0; let mut three = 0; for i in 0..c { if rem[i] == 1 { one |= 1 << i; } if rem[i] == 2 { two |= 1 << i; } if rem[i] >= 3 { three |= 1 << i; } } let to = memo[one | three][two | three]; ep[to] += sum * pr; epx[to] += sumx * pr + sum * pr * to.count_ones() as f64; for j in 0..c { if (pre & 1 << j) != 0 { rem[j] += 1; } } } } dp = ep; dpx = epx; } let s: f64 = dpx.iter().sum(); println!("{}", s); }