結果

問題 No.2222 Respawn
ユーザー chineristACchineristAC
提出日時 2023-02-17 23:07:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,695 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 100,656 KB
最終ジャッジ日時 2023-09-26 20:28:19
合計ジャッジ時間 7,016 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
74,240 KB
testcase_01 AC 115 ms
74,476 KB
testcase_02 AC 112 ms
74,724 KB
testcase_03 AC 114 ms
74,332 KB
testcase_04 AC 113 ms
74,360 KB
testcase_05 AC 112 ms
74,512 KB
testcase_06 AC 111 ms
74,696 KB
testcase_07 AC 112 ms
74,300 KB
testcase_08 AC 114 ms
74,456 KB
testcase_09 AC 114 ms
74,328 KB
testcase_10 AC 116 ms
74,476 KB
testcase_11 AC 112 ms
74,148 KB
testcase_12 AC 116 ms
74,472 KB
testcase_13 AC 149 ms
91,024 KB
testcase_14 AC 154 ms
88,640 KB
testcase_15 AC 144 ms
83,552 KB
testcase_16 AC 153 ms
87,796 KB
testcase_17 AC 144 ms
83,300 KB
testcase_18 AC 170 ms
97,532 KB
testcase_19 AC 169 ms
97,400 KB
testcase_20 AC 170 ms
98,348 KB
testcase_21 AC 172 ms
97,620 KB
testcase_22 AC 169 ms
97,448 KB
testcase_23 AC 173 ms
97,384 KB
testcase_24 AC 171 ms
97,308 KB
testcase_25 AC 171 ms
97,140 KB
testcase_26 AC 172 ms
97,208 KB
testcase_27 AC 169 ms
97,272 KB
testcase_28 AC 171 ms
100,264 KB
testcase_29 AC 175 ms
100,436 KB
testcase_30 AC 175 ms
100,656 KB
testcase_31 AC 145 ms
95,336 KB
testcase_32 AC 203 ms
95,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N = int(input())
S = input().rstrip()
S += "#"

dp = [10**15] * N
dp[N-1] = 0

dp_save = [0] * N
dp_save_p = [0] * N

dp_back_p = [0] * N
dp_back_e = [0] * N

for i in range(N-1)[::-1]:
    if S[i]=="#":
        continue

    if i+1 <= N and S[i+1]==".":
        if i+1 != N-1:
            dp_back_p[i] += dp_back_p[i+1]/3
            dp_back_e[i] += (dp_back_p[i+1]+dp_back_e[i+1])/3
            dp_save[i] += 1/9 * (2+dp[i+1]) + 1/3 * (dp_save_p[i+1]+dp_save[i+1])
            dp_save_p[i] += 1/9 + 1/3 * dp_save_p[i+1]
        else:
            dp_save[i] += 1/3
            dp_save_p[i] += 1/3
    elif i+1 <= N:
        dp_back_p[i] += 1/3
        dp_back_e[i] += 1/3

    if i+2 <= N and S[i+2]==".":
        if i+2 != N-1:
            dp_back_p[i] += dp_back_p[i+2]/3
            dp_back_e[i] += (dp_back_p[i+2]+dp_back_e[i+2])/3
            dp_save[i] += 1/9 * (2+dp[i+2]) + 1/3 * (dp_save_p[i+2]+dp_save[i+2])
            dp_save_p[i] += 1/9 + 1/3 * dp_save_p[i+2]
        else:
            dp_save[i] += 1/3
            dp_save_p[i] += 1/3
    elif i+2 <= N:
        dp_back_p[i] += 1/3
        dp_back_e[i] += 1/3
    
    """
    dp[i] = 1/3 * (1+dp[i]) + dp_save[i] + dp_back_p[i] * dp[i] + dp_back_e[i]
    """

    #print(dp_save[i],dp_back_e[i],dp_back_p[i])
    #print(dp_save_p[i]+dp_back_p[i])

    dp[i] = (1/3+dp_save[i]+dp_back_e[i]) / (2/3-dp_back_p[i])
    #print(dp[i])

print(dp[0])


    
0