結果

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

ソースコード

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);

    // exp value of remaining teeth for consecutive i teeth
    let mut dp = (0..=N).into_iter().map(|x| x as f64).collect::<Vec<_>>();

    for _ in 0..80 - a {
        let mut ndp = vec![0.0; N + 1];
        ndp[1] = dp[1] * (1.0 - p0);

        for ln in 2..=N {
            let mut ans = 0.0;
            let mut prob = vec![1.0];
            for j in 0..ln {
                prob.push(0.0);
                let p = if j == 0 || j == ln - 1 { p1 } else { p2 };
                let mut p0 = 0.0;
                for k in (0..=j).rev() {
                    ans += p * dp[k] * prob[k];
                    prob[k + 1] = (1.0 - p) * prob[k];
                    p0 += p * prob[k];
                }
                prob[0] = p0;
            }

            for j in 0..=ln {
                ans += dp[j] * prob[j];
            }

            ndp[ln] = ans;
        }

        dp = ndp;
    }

    println!("{:.9}", 2.0 * dp[N]);
}

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