結果

問題 No.309 シャイな人たち (1)
ユーザー t98slidert98slider
提出日時 2023-05-16 02:23:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,791 bytes
コンパイル時間 1,788 ms
コンパイル使用メモリ 174,080 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-20 23:35:16
合計ジャッジ時間 34,820 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 WA -
testcase_03 AC 2,994 ms
4,380 KB
testcase_04 AC 30 ms
4,376 KB
testcase_05 AC 503 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<vector<double>> P(h, vector<double>(w));
    vector<vector<int>> S(h, vector<int>(w));
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            cin >> P[y][x];
            P[y][x] /= 100;
        }
    }
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            cin >> S[y][x];
        }
    }

    vector<double> pre(1 << w);
    pre[0] = 1;
    auto f = [&](int S0, int S1, int x){
        int cnt = 0;
        cnt += (S0 >> x) & 1;
        if(x) cnt += (S1 >> x - 1) & 1;
        cnt += (S1 >> x + 1) & 1;
        return cnt;
    };
    double ans = 0;
    for(int y = 0; y < h; y++){
        //前の列手を挙げている人がS0でS1に遷移する確率
        vector<double> dp(1 << w);
        for(int S0 = 0; S0 < (1 << w); S0++){
            if(pre[S0] == 0) continue;
            for(int S1 = 0; S1 < (1 << w); S1++){
                double p = pre[S0], p0, p1;
                for(int x = 0; x < w; x++){
                    p0 = p1 = 0;
                    int c = f(S0, S1, x);

                    if(S1 >> x & 1){
                        if(4 - S[y][x] + c >= 4) p0 = P[y][x] * p;
                        if(c >= 4) p1 = (1 - P[y][x]) * p;
                    }else{
                        if(4 - S[y][x] + c < 4) p0 = P[y][x] * p;
                        if(c < 4) p1 = (1 - P[y][x]) * p;
                    }
                    p = p0 + p1;
                }
                dp[S1] += p;
                ans += p * __builtin_popcount(S1);
            }
        }
        swap(pre, dp);
    }
    cout << fixed << setprecision(15) << ans << '\n';
}
0