結果

問題 No.309 シャイな人たち (1)
ユーザー eitahoeitaho
提出日時 2015-12-02 19:57:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,170 ms / 4,000 ms
コード長 2,944 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 78,032 KB
実行使用メモリ 20,016 KB
最終ジャッジ日時 2023-10-12 09:02:49
合計ジャッジ時間 17,121 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,102 ms
20,008 KB
testcase_01 AC 1,788 ms
19,920 KB
testcase_02 AC 375 ms
19,944 KB
testcase_03 AC 1,397 ms
20,016 KB
testcase_04 AC 19 ms
4,352 KB
testcase_05 AC 268 ms
9,760 KB
testcase_06 AC 372 ms
19,928 KB
testcase_07 AC 411 ms
20,000 KB
testcase_08 AC 1,436 ms
19,924 KB
testcase_09 AC 1,724 ms
20,000 KB
testcase_10 AC 2,170 ms
19,924 KB
testcase_11 AC 1,877 ms
19,928 KB
testcase_12 AC 1,500 ms
19,928 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 85 ms
9,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <climits>
#include <numeric>
#include <functional>
#include <time.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
template<class T> void checkmin(T &a, T b) { if (b < a) a = b; }
template<class T> void checkmax(T &a, T b) { if (b > a) a = b; }


const int MaxSize = 11;
const int Threshold = 4;
int H, W;
double Prob[MaxSize][MaxSize];
int Val[MaxSize][MaxSize];
int AtLast[1 << MaxSize * 2];
double dp[1 << MaxSize], nextdp[1 << MaxSize];


void simulate() {
    int S = 1 << W * 2;
    int pt[MaxSize];
    int who[MaxSize], nextWho[MaxSize];

    rep(mask, S) {
        int num = 0;
        for (int c = 0; c < W; c++) {
            pt[c] = 1 + (mask >> c * 2 & 3);
            if (pt[c] == Threshold) {
                who[num++] = c;
                AtLast[mask] += 1 << c;
            }
        }
        while (num > 0) {
            int nextNum = 0;
            rep(i, num) {
                int c = who[i];
                if (c - 1 >= 0 && ++pt[c - 1] == Threshold) {
                    nextWho[nextNum++] = c - 1; AtLast[mask] += 1 << c - 1;
                }
                if (c + 1 < W && ++pt[c + 1] == Threshold) {
                    nextWho[nextNum++] = c + 1; AtLast[mask] += 1 << c + 1;
                }
            }
            swap(who, nextWho);
            num = nextNum;
        }
    }
}

void solve() {
    simulate();
    dp[0] = 1;
    double ans = 0;

    rep(r, H) {
        memset(nextdp, 0, sizeof(nextdp));
        rep(currMask, 1 << W) {
            double currMaskProb = 1;
            rep(c, W) {
                if (currMask >> c & 1) currMaskProb *= Prob[r][c];
                else currMaskProb *= 1 - Prob[r][c];
            }
            rep(prevMask, 1 << W) if (dp[prevMask] > 0) {
                double p = dp[prevMask] * currMaskProb;
                int key = 0;
                rep(c, W) {
                    int pt = Val[r][c] * (currMask >> c & 1);
                    if (r > 0) pt += prevMask >> c & 1;
                    key |= max(0, min(Threshold, pt) - 1) << c * 2;
                }
                int nextMask = AtLast[key];
                ans += p * __builtin_popcount(nextMask);
                nextdp[nextMask] += p;
            }
        }
        swap(dp, nextdp);
    }

    printf("%.11f\n", ans);
}

int main() {
    cin >> H >> W;
    rep(r, H) rep(c, W) {
        cin >> Prob[r][c];
        Prob[r][c] /= 100.0;
    }
    rep(r, H) rep(c, W) {
        cin >> Val[r][c];
        Val[r][c] = Threshold - Val[r][c];
    }
    solve();

    return 0;
}
0