結果

問題 No.162 8020運動
ユーザー nebukuro09nebukuro09
提出日時 2018-06-14 09:41:50
言語 D
(dmd 2.106.1)
結果
MLE  
実行時間 -
コード長 1,559 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 161,408 KB
実行使用メモリ 645,720 KB
最終ジャッジ日時 2023-09-03 20:24:38
合計ジャッジ時間 14,568 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,675 ms
388,908 KB
testcase_01 AC 1,491 ms
387,472 KB
testcase_02 MLE -
testcase_03 MLE -
testcase_04 TLE -
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 #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    immutable int T = 14;
    auto N = readln.chomp.to!int;
    auto P = readln.split.map!(a => a.to!int / 100.0L).array;
    auto trans = new real[int][](1<<T);

    for (int m1 = 0; m1 < (1 << T); ++m1) {
        for(int m2 = m1; m2 >= 0; --m2) {
            m2 &= m1;
            real tmp = 1;
            for (int i = 0; i < T; ++i) {
                if ((1 << i) & m1) {
                    bool l = (i != 0) && ((1 << (i-1)) & m1);
                    bool r = (i != T-1) && ((1 << (i+1)) & m1);
                    real safe;
                    if (l && r)
                        safe = 1 - P[2];
                    else if (l || r)
                        safe = 1 - P[1];
                    else
                        safe = 1 - P[0];
                    tmp *=  ((1 << i) & m2) ? safe : 1 - safe;
                }
            }
            trans[m1][m2] = tmp;
        }
    }

    auto dp = new real[][](80-N+1, 1<<T);
    foreach (i; 0..80-N+1) dp[i].fill(0);
    dp[0][(1<<T)-1] = 1;

    foreach (i; 0..80-N) {
        foreach (m1; 0..(1<<T)) {
            if (dp[i][m1] == 0)
                continue;
            foreach (m2; trans[m1].keys)
                dp[i+1][m2] += dp[i][m1] * trans[m1][m2];
        }
    }

    real ans = 0;
    foreach (mask; 0..(1<<T))
        ans += dp[80-N][mask] * mask.popcnt;
    writefln("%.09f", ans*2);
}
0