結果

問題 No.309 シャイな人たち (1)
ユーザー しらっ亭しらっ亭
提出日時 2015-12-08 22:16:43
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,701 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 87,132 KB
最終ジャッジ日時 2023-10-12 22:10:54
合計ジャッジ時間 10,800 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def bitcount(x):
    """
    立っているbitの数
    """
    x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555)
    x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333)
    x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f)
    x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff)
    x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff)
    return (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff)


def calc(i, j, s, C):
    """
    :param i: 自分たちの行の知ってる知ってないの状態
    :param j: 前の行の挙げてる挙げてないの状態
    :param s: 自分たちの行のシャイ度
    :param C: 横幅
    :return: 自分たちがどのような挙手状態になるか
    """

    ret = 0
    p = [0] * C
    for c in range(C):
        c1 = 1 << c
        if i & c1:
            p[c] = 4 - s[c]
            if j & c1:
                p[c] += 1
            if p[c] >= 4:
                ret |= c1

    pret = 0
    while pret != ret:
        for c in range(C):
            c1 = 1 << c
            if ret & c1 and pret ^ c1:
                if c > 0:
                    p[c - 1] += 1
                    if p[c - 1] >= 4:
                        ret |= 1 << (c - 1)
                if c < C - 1:
                    p[c + 1] += 1
                    if p[c + 1] >= 4:
                        ret |= 1 << (c + 1)
        pret = ret
    # print((bin(i), bin(j), s, bin(ret)))
    return ret


def solve():
    R, C = map(int, input().split())
    P = []
    S = []

    input()
    for r in range(R):
        P.append(list(map(int, input().split())))
    input()
    for r in range(R):
        S.append(list(map(int, input().split())))
    ans = 0

    Y = [[0.0] * (1 << C) for r in range(R)]
    # Y[r][i]: r 行目の手を挙げる挙げないの組み合わせが i になる確率

    for r in range(R):
        yr = Y[r]

        for i in range(1 << C):
            x = 1.0
            for c in range(C):
                if i & (1 << c):
                    x *= P[r][c] / 100
                else:
                    x *= (100 - P[r][c]) / 100

            # x: 自分たちの知ってる知ってないの組み合わせが i になる確率

            for j in range(1 << C):
                if r > 0:
                    y = Y[r - 1][j]
                elif j == 0:
                    y = 1.0
                else:
                    continue

                z = calc(i, j, S[r], C)
                yr[z] += y * x

        for i in range(1 << C):
            # print((bin(i), bitcount(i), yr[i]))
            ans += bitcount(i) * yr[i]
    print(ans)


if __name__ == '__main__':
    solve()
0