結果

問題 No.162 8020運動
ユーザー koba-e964koba-e964
提出日時 2017-02-07 01:20:40
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 2,404 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 154,988 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-25 22:17:25
合計ジャッジ時間 15,542 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 383 ms
4,380 KB
testcase_01 AC 3,867 ms
4,380 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

fn main() {
    let n = 80 - get::<usize>();
    let p0: f64 = get::<f64>() / 100.0;
    let p1: f64 = get::<f64>() / 100.0;
    let p2: f64 = get::<f64>() / 100.0;
    const B: usize = 14;
    let mut dp = vec![vec![0.0; 1 << B]; n + 1];
    dp[0][(1 << B) - 1] = 1.0;
    for i in 0 .. n {
        for b1 in 0 .. 1 << B {
            let mut b2 = b1;
            loop {
                let mut prob = 1.0;
                for j in 0 .. B {
                    if (b1 & 1 << j) == 0 { continue; }
                    let p;
                    let mut adj = 0;
                    if j == 0 || (j >= 1 && (b1 & 1 << (j - 1)) == 0) {
                        adj += 1;
                    }
                    if j == B - 1 || (j < B - 1 && (b1 & 1 << (j + 1)) == 0) {
                        adj += 1;
                    }
                    p = match adj {
                        0 => p2,
                        1 => p1,
                        2 => p0,
                        _ => panic!(),
                    };
                    prob *= if (b2 & 1 << j) == 0 { p } else { 1.0 - p };
                }
                dp[i + 1][b2] += prob * dp[i][b1];
                if b2 == 0 {
                    break;
                }
                b2 = (b2 - 1) & b1;
            }
        }
    }
    let mut tot = 0.0;
    for i in 0 .. 1 << B {
        tot += ((i as u32).count_ones() as f64) * dp[n][i];
    }
    println!("{}", 2.0 * tot);
}
0