結果

問題 No.162 8020運動
ユーザー koba-e964koba-e964
提出日時 2017-02-07 09:10:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,345 ms / 5,000 ms
コード長 3,169 bytes
コンパイル時間 5,883 ms
コンパイル使用メモリ 153,576 KB
実行使用メモリ 7,124 KB
最終ジャッジ日時 2023-08-25 22:42:08
合計ジャッジ時間 30,617 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
4,704 KB
testcase_01 AC 622 ms
5,800 KB
testcase_02 AC 929 ms
6,584 KB
testcase_03 AC 1,232 ms
7,036 KB
testcase_04 AC 1,232 ms
7,012 KB
testcase_05 AC 1,239 ms
7,100 KB
testcase_06 AC 1,238 ms
7,108 KB
testcase_07 AC 1,234 ms
7,104 KB
testcase_08 AC 1,237 ms
7,104 KB
testcase_09 AC 67 ms
4,708 KB
testcase_10 AC 925 ms
6,568 KB
testcase_11 AC 691 ms
5,768 KB
testcase_12 AC 320 ms
5,216 KB
testcase_13 AC 1,315 ms
7,124 KB
testcase_14 AC 128 ms
4,696 KB
testcase_15 AC 129 ms
4,744 KB
testcase_16 AC 376 ms
5,212 KB
testcase_17 AC 190 ms
4,992 KB
testcase_18 AC 1,345 ms
7,108 KB
testcase_19 AC 867 ms
6,220 KB
testcase_20 AC 1,125 ms
6,592 KB
testcase_21 AC 981 ms
6,568 KB
testcase_22 AC 933 ms
6,548 KB
testcase_23 AC 989 ms
6,592 KB
testcase_24 AC 927 ms
6,528 KB
testcase_25 AC 1,048 ms
6,844 KB
testcase_26 AC 67 ms
4,740 KB
testcase_27 AC 683 ms
6,032 KB
testcase_28 AC 1,179 ms
7,008 KB
権限があれば一括ダウンロードができます

ソースコード

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 decay = vec![vec![0.0; B]; 1 << B];
    for bits in 0 .. 1 << B {
        for j in 0 .. B {
            if (bits & 1 << j) == 0 { continue; }
            let p;
            let mut adj = 0;
            if j == 0 || (j >= 1 && (bits & 1 << (j - 1)) == 0) {
                adj += 1;
            }
            if j == B - 1 || (j < B - 1 && (bits & 1 << (j + 1)) == 0) {
                adj += 1;
            }
            p = match adj {
                0 => p2,
                1 => p1,
                2 => p0,
                _ => panic!(),
            } + 1e-8;
            decay[bits][j] = p;
        }
    }
    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;
            let mut prob = 1.0;
            for j in 0 .. B {
                if (b1 & 1 << j) == 0 { continue; }
                prob *= 1.0 - decay[b1][j];
            }
            loop {
                /*
                for j in 0 .. B {
                    if (b1 & 1 << j) == 0 { continue; }
                    let p = decay[b1][j];
                    prob *= if (b2 & 1 << j) == 0 { p } else { 1.0 - p };
                }
                 */
                dp[i + 1][b2] += prob * dp[i][b1];
                if b2 == 0 {
                    break;
                }
                let newb2 = (b2 - 1) & b1;
                for j in 0 .. B {
                    if (b1 & 1 << j) == 0 { continue; }
                    if (b2 & 1 << j) == (newb2 & 1 << j) { break; }
                    if (newb2 & 1 << j) == 0 {
                        prob *= decay[b1][j] / (1.0 - decay[b1][j]);
                    } else {
                        prob *= (1.0 - decay[b1][j]) / decay[b1][j];
                    }
                }
                b2 = newb2;
            }
        }
    }
    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