結果

問題 No.162 8020運動
ユーザー nebukuro09nebukuro09
提出日時 2018-06-14 10:10:29
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2,201 ms / 5,000 ms
コード長 1,696 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 135,920 KB
実行使用メモリ 200,328 KB
最終ジャッジ日時 2023-08-20 10:51:05
合計ジャッジ時間 46,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,006 ms
200,184 KB
testcase_01 AC 993 ms
200,208 KB
testcase_02 AC 1,873 ms
200,148 KB
testcase_03 AC 1,696 ms
200,184 KB
testcase_04 AC 2,179 ms
200,240 KB
testcase_05 AC 2,201 ms
200,240 KB
testcase_06 AC 2,201 ms
200,116 KB
testcase_07 AC 2,194 ms
200,136 KB
testcase_08 AC 2,196 ms
200,180 KB
testcase_09 AC 998 ms
200,188 KB
testcase_10 AC 1,005 ms
200,188 KB
testcase_11 AC 997 ms
200,328 KB
testcase_12 AC 1,001 ms
200,180 KB
testcase_13 AC 998 ms
200,212 KB
testcase_14 AC 1,003 ms
200,140 KB
testcase_15 AC 1,008 ms
200,156 KB
testcase_16 AC 1,192 ms
200,292 KB
testcase_17 AC 1,006 ms
200,204 KB
testcase_18 AC 1,013 ms
200,204 KB
testcase_19 AC 1,821 ms
200,116 KB
testcase_20 AC 1,007 ms
200,180 KB
testcase_21 AC 1,964 ms
200,180 KB
testcase_22 AC 1,003 ms
200,244 KB
testcase_23 AC 1,951 ms
200,208 KB
testcase_24 AC 1,884 ms
200,116 KB
testcase_25 AC 2,009 ms
200,128 KB
testcase_26 AC 1,007 ms
200,176 KB
testcase_27 AC 1,665 ms
200,316 KB
testcase_28 AC 1,687 ms
200,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;
typedef long double ld;

unordered_map<int, double> trans[1<<14];
double dp[2][1<<14];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    const int T = 14;
    int N;
    double P[3];
    cin >> N;
    REP(i, 3) cin >> P[i], P[i] /= 100.0;

    for (int m1 = 0; m1 < (1 << T); ++m1) {
        for(int m2 = m1; m2 >= 0; --m2) {
            m2 &= m1;
            double 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);
                    double 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;
        }
    }

    REP(i, 2) REP(j, 1<<T) dp[i][j] = 0;
    dp[0][(1<<T)-1] = 1;
    int cur = 0, tar = 1;

    REP(i, 80-N) {
        REP(j, 1<<T)
            dp[tar][j] = 0;
        REP(m1, 1<<T) {
            if (dp[cur][m1] == 0)
                continue;
            for (auto itr: trans[m1])
                dp[tar][itr.first] += dp[cur][m1] * itr.second;
        }
        swap(cur, tar);
    }

    double ans = 0;
    REP(mask, 1<<T)
        ans += dp[cur][mask] * __builtin_popcount(mask);
    cout.precision(20);
    cout << fixed  << ans*2 << endl;
}

0