結果
問題 | No.309 シャイな人たち (1) |
ユーザー | koba-e964 |
提出日時 | 2021-11-22 18:12:29 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,079 bytes |
コンパイル時間 | 13,613 ms |
コンパイル使用メモリ | 394,504 KB |
実行使用メモリ | 48,576 KB |
最終ジャッジ日時 | 2024-06-24 06:13:35 |
合計ジャッジ時間 | 24,316 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
ソースコード
#[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(rem: &[i32]) -> usize { let c = rem.len(); let mut vis = 0; let mut que = vec![]; for i in 0..c { if rem[i] <= 0 { vis |= 1 << i; } } for i in 0..c { if rem[i] <= 2 && ((vis << 1) & (5 << i)) != 0 && (vis & 1 << i) == 0 { que.push(i); } } while let Some(v) = que.pop() { if (vis & 1 << v) != 0 { continue; } let adj = ((vis << 1) & (5 << v)) >> v; let x = match adj { 0 => 0, 1 | 4 => 1, 5 => 2, _ => panic!(), }; if rem[v] <= x { vis |= 1 << v; if v + 1 < c && rem[v + 1] <= 2 { que.push(v + 1); } if v > 0 && rem[v - 1] <= 2 { que.push(v - 1); } } } vis } 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(&rem); } } } 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); }