結果

問題 No.58 イカサマなサイコロ
ユーザー kutsutamakutsutama
提出日時 2018-03-25 13:33:58
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 122 ms / 5,000 ms
コード長 830 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 9,128 KB
最終ジャッジ日時 2023-09-07 11:40:09
合計ジャッジ時間 1,291 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,784 KB
testcase_01 AC 122 ms
9,128 KB
testcase_02 AC 16 ms
7,748 KB
testcase_03 AC 17 ms
7,828 KB
testcase_04 AC 27 ms
8,380 KB
testcase_05 AC 32 ms
8,316 KB
testcase_06 AC 69 ms
8,724 KB
testcase_07 AC 17 ms
7,672 KB
testcase_08 AC 20 ms
8,300 KB
testcase_09 AC 37 ms
8,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, k, num, taro, jiro, memo):
    if num >= n:
        if taro > jiro:
            memo[n][(taro, jiro)] = 1
            return 1
        else:
            memo[n][(taro, jiro)] = 0
            return 0
    if (taro, jiro) in memo[num]:
        return memo[num][(taro, jiro)]

    res = 0
    if num < k:
        for i in range(4, 7):
            for j in range(1, 7):
                res += solve(n, k, num + 1, taro + i, jiro + j, memo)
        res *= 2
    else:
        for i in range(1, 7):
            for j in range(1, 7):
                res += solve(n, k, num + 1, taro + i, jiro + j, memo)
    memo[num][(taro, jiro)] = res
    return res

n = int(input())
k = int(input())

memo = [{} for x in range(n + 1)]
win = solve(n, k, 0, 0, 0, memo)
res = win / 6**n / 6**n

print(res)
0