結果

問題 No.162 8020運動
ユーザー titia
提出日時 2025-07-10 02:20:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,460 ms / 5,000 ms
コード長 1,651 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 82,792 KB
実行使用メモリ 383,100 KB
最終ジャッジ日時 2025-07-10 02:22:33
合計ジャッジ時間 118,920 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

A=int(input())
P=list(map(int,input().split()))

for i in range(3):
    P[i]/=100

TO=[[] for i in range(1<<14)]

for i in range(1<<14):
    for to in range(1<<14):
        if (i & to) == to:
            prob=1

            for j in range(14):
                if i & (1<<j) == 0:
                    continue

                count=0
                
                if j==0:
                    if i & (1<<1) != 0:
                        count+=1
                elif j==13:
                    if i & (1<<12) != 0:
                        count+=1
                else:
                    count=0

                    if i & (1<<(j-1)) != 0:
                        count+=1

                    if i & (1<<(j+1)) != 0:
                        count+=1

                if count==0:
                    if to & (1<<j) != 0:
                        prob=prob*(1-P[0])
                    else:
                        prob=prob*P[0]
                elif count == 1:
                    if to & (1<<j) != 0:
                        prob=prob*(1-P[1])
                    else:
                        prob=prob*P[1]
                else:
                    if to & (1<<j) != 0:
                        prob=prob*(1-P[2])
                    else:
                        prob=prob*P[2]

            TO[i].append((to,prob))
                        
DP=[0]*(1<<14)
DP[-1]=1

for tests in range(80-A):
    NDP=[0]*(1<<14)

    for i in range(1<<14):
        for to,prob in TO[i]:
            NDP[to]+=DP[i]*prob

    DP=NDP

ANS=0

for i in range(1<<14):
    x=i.bit_count()
    ANS+=x*DP[i]

print(ANS*2)

    
0