結果

問題 No.1590 Random Shopping
ユーザー rin204rin204
提出日時 2022-01-26 20:51:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 642 ms / 5,000 ms
コード長 1,359 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 77,184 KB
最終ジャッジ日時 2024-06-06 04:03:41
合計ジャッジ時間 7,089 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 41 ms
51,712 KB
testcase_02 AC 41 ms
51,840 KB
testcase_03 AC 39 ms
51,968 KB
testcase_04 AC 41 ms
52,224 KB
testcase_05 AC 39 ms
52,224 KB
testcase_06 AC 39 ms
51,968 KB
testcase_07 AC 42 ms
52,864 KB
testcase_08 AC 80 ms
62,080 KB
testcase_09 AC 76 ms
70,400 KB
testcase_10 AC 97 ms
76,288 KB
testcase_11 AC 109 ms
76,672 KB
testcase_12 AC 133 ms
76,288 KB
testcase_13 AC 219 ms
77,184 KB
testcase_14 AC 452 ms
76,544 KB
testcase_15 AC 454 ms
76,632 KB
testcase_16 AC 471 ms
76,640 KB
testcase_17 AC 642 ms
76,652 KB
testcase_18 AC 39 ms
51,712 KB
testcase_19 AC 518 ms
76,288 KB
testcase_20 AC 40 ms
51,712 KB
testcase_21 AC 288 ms
76,416 KB
testcase_22 AC 39 ms
51,712 KB
testcase_23 AC 608 ms
76,912 KB
testcase_24 AC 476 ms
76,888 KB
testcase_25 AC 40 ms
51,712 KB
testcase_26 AC 40 ms
52,224 KB
testcase_27 AC 40 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))
R = list(map(int, input().split()))
ans = 0
for i in range(n):
    dp = [1]
    for j in range(n):
        if i == j:
            l = len(dp)
            ans += R[j] * A[i] * dp[0] / 2
            dp2 = [0] * l
            for k in range(l):
                dp2[k] += dp[k] / 2
                if k != 0:
                    dp2[k - 1] += dp[k] / 2
            dp = dp2
        elif j < i:
            l = len(dp)
            if A[j] <= A[i]:
                dp2 = [0] * (l + 1)
                for k in range(l):
                    dp2[k] += dp[k] / 2
                    dp2[k + 1] += dp[k] / 2
            else:
                dp2 = [0] * l
                for k in range(l):
                    dp2[k] += dp[k] / 2
                    dp2[max(0, k - 1)] += dp[k] / 2
            dp = dp2
        else:
            l = len(dp)
            if A[j] < A[i]:
                dp2 = [0] * (l + 1)
                for k in range(l):
                    dp2[k] += dp[k] / 2
                    dp2[k + 1] += dp[k] / 2
            else:
                ans += R[j] * A[i] * dp[0] / 2
                dp2 = [0] * l
                for k in range(l):
                    dp2[k] += dp[k] / 2
                    if k != 0:
                        dp2[k - 1] += dp[k] / 2
            dp = dp2
        
print(ans)

0