結果

問題 No.162 8020運動
コンテスト
ユーザー cologne
提出日時 2026-02-05 12:20:14
言語 Rust
(1.93.0 + proconio + num + itertools)
結果
TLE  
実行時間 -
コード長 3,393 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,069 ms
コンパイル使用メモリ 210,136 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-02-05 12:20:33
合計ジャッジ時間 18,606 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other TLE * 1 -- * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use fio::*;

const N: usize = 14;
fn main() {
    let a = read::<i32>();
    let [p0, p1, p2] = read_tuple::<i32, 3>();
    let (p0, p1, p2) = (p0 as f64 / 100.0, p1 as f64 / 100.0, p2 as f64 / 100.0);
    let mut dp = vec![0.0; 1 << N];
    dp[(1 << N) - 1] = 1.0;
    for _ in 0..80 - a {
        let mut ndp = vec![0.0; 1 << N];
        for i in 0..1 << N {
            let mut pp = vec![0f64; N];
            for k in 0..N {
                let val = ((i << 1) >> k) & 5;
                pp[k] = match val {
                    0 => p0,
                    1 | 4 => p1,
                    5 => p2,
                    _ => unreachable!(),
                }
            }
            let mut j = i;
            loop {
                let mut prob = 1.0;
                for k in 0..N {
                    if i & (1 << k) == 0 {
                        continue;
                    }
                    prob *= if j & (1 << k) == 0 {
                        pp[k]
                    } else {
                        1.0 - pp[k]
                    }
                }
                ndp[j] += prob * dp[i];

                if j == 0 {
                    break;
                } else {
                    j = (j - 1) & i;
                }
            }
        }
        dp = ndp;
    }
    eprintln!("{:?}", &dp);
    let ans = 2.0
        * dp.into_iter()
            .enumerate()
            .map(|(i, x)| i.count_ones() as f64 * x)
            .sum::<f64>();
    println!("{ans:.9}");
}

mod fio {
    use std::{
        cell::RefCell,
        convert::TryInto,
        fmt::Debug,
        io::{BufRead, BufWriter, StdinLock, StdoutLock, stdin, stdout},
        str::FromStr,
    };
    thread_local! {
        pub static STDIN: RefCell<StdinLock<'static>> = RefCell::new(stdin().lock());
        pub static STDOUT: RefCell<BufWriter<StdoutLock<'static>>> = RefCell::new(BufWriter::new(stdout().lock()));
    }

    #[allow(dead_code)]
    pub fn read<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        read_line().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn read_vec<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        read_line()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn read_tuple<T, const N: usize>() -> [T; N]
    where
        T: FromStr + Debug,
        <T as FromStr>::Err: Debug,
    {
        read_vec::<T>().try_into().unwrap()
    }

    /// whitespace at the end of the line is ignored
    pub fn read_line() -> String {
        let mut s = String::new();
        STDIN.with(|cell| {
            cell.borrow_mut().read_line(&mut s).unwrap();
        });
        String::from_str(s.trim_end()).unwrap()
    }
}

#[macro_export]
macro_rules! print {
    ($($t:tt)*) => {
        fio::STDOUT.with(|cell|{
            use std::io::Write;
            write!(cell.borrow_mut(), $($t)*).unwrap()
        })};
}

#[macro_export]
macro_rules! println {
    ($($t:tt)*) => {
        fio::STDOUT.with(|cell| {
            use std::io::Write;
            writeln!(cell.borrow_mut(), $($t)*).unwrap()
        })
    };
}

#[macro_export]
macro_rules! flush {
    () => {
        fio::STDOUT.with(|cell| {
            use std::io::Write;
            cell.borrow_mut().flush().unwrap()
        });
    };
}
0