結果
問題 | No.1151 チャレンジゲーム |
ユーザー | fukafukatani |
提出日時 | 2020-08-15 00:23:56 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,985 bytes |
コンパイル時間 | 13,229 ms |
コンパイル使用メモリ | 378,948 KB |
実行使用メモリ | 59,392 KB |
最終ジャッジ日時 | 2024-10-10 16:58:03 |
合計ジャッジ時間 | 18,287 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | WA | - |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 105 ms
59,264 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | AC | 106 ms
59,392 KB |
testcase_49 | AC | 106 ms
59,264 KB |
testcase_50 | WA | - |
testcase_51 | AC | 104 ms
59,392 KB |
testcase_52 | WA | - |
ソースコード
#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn infinite_sum(a: f64, r: f64) -> f64 { a / (1. - r) } fn main() { let n = read::<usize>(); let a = read_vec::<i64>(); let a_prob = a .iter() .map(|&x| { infinite_sum( 1.0 / x as f64, (1.0 - 1.0 / x as f64) * (1.0 - 1.0 / x as f64), ) }) .collect::<Vec<_>>(); debug!(a_prob); let asum = a.iter().sum::<i64>(); let mut dp = vec![vec![vec![0.0; 2]; 1 << n]; 1 << n]; for state in 0..1 << n { let mut kiri_score = 0; for j in 0..n { if (state >> j) & 1 == 1 { kiri_score += a[j]; } if kiri_score >= asum - kiri_score { for k in 0..2 { dp[(1 << n) - 1][state][k] = 1.0; } } } } for s_state in (0..(1 << n) - 1).rev() { 'p: for p_state in 0..1 << n { for j in 0..n { if (s_state >> j) & 1 == 0 && (p_state >> j) & 1 == 1 { continue 'p; } } let unselected = (0..n) .filter(|&x| (s_state >> x) & 1 == 0) .collect::<Vec<_>>(); // cur senkou let mut temp = 0.0; for &ai in &unselected { let next_s_state = s_state | (1 << ai); let next_p_state = p_state | (1 << ai); let prob = a_prob[ai]; temp = f64::max( temp, prob * dp[next_s_state][next_p_state][1] + (1.0 - prob) * dp[next_s_state][p_state][0], ); } dp[s_state][p_state][0] = temp; let mut temp = 1.0; for &ai in &unselected { let next_s_state = s_state | (1 << ai); let next_p_state = p_state | (1 << ai); let prob = a_prob[ai]; temp = f64::min( temp, (1.0 - prob) * dp[next_s_state][next_p_state][1] + prob * dp[next_s_state][p_state][0], ); } dp[s_state][p_state][1] = temp; } } let ans = 1.0 - dp[0][0][1]; println!("{}", ans); } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }