結果

問題 No.58 イカサマなサイコロ
ユーザー バカらっくバカらっく
提出日時 2019-09-19 12:32:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,560 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 8,420 KB
最終ジャッジ日時 2023-09-26 00:09:05
合計ジャッジ時間 1,203 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,360 KB
testcase_01 AC 19 ms
8,332 KB
testcase_02 AC 16 ms
8,420 KB
testcase_03 AC 18 ms
8,408 KB
testcase_04 AC 17 ms
8,328 KB
testcase_05 AC 18 ms
8,268 KB
testcase_06 AC 17 ms
8,328 KB
testcase_07 AC 17 ms
8,396 KB
testcase_08 AC 17 ms
8,364 KB
testcase_09 AC 19 ms
8,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

totalDice = int(input())
ikasamaDice = int(input())

dic = [None for i in range(10)]


def getPattern(index):
    if index >= totalDice - 1:
        return dict([(i + 1, 1) for i in range(6)])
    if dic[index] is not None:
        return dic[index]

    ans = {}
    ret = getPattern(index + 1)
    for i, j in ret.items():
        for k in [l + 1 for l in range(6)]:
            key = i + k
            if key in ans.keys():
                ans[key] += j
            else:
                ans[key] = j
    dic[index] = ans
    return ans


ikasamaDic = [None for i in range(10)]


def getIkasamaPattern(index):
    if index >= ikasamaDice:
        return getPattern(index)
    if index >= totalDice - 1:
        return dict([(i + 4, 2) for i in range(3)])
    if ikasamaDic[index] is not None:
        return dic[index]

    ans = {}
    ret = getIkasamaPattern(index + 1)
    for i, j in ret.items():
        for k in [(l % 3) + 4 for l in range(6)]:
            key = i + k
            if key in ans.keys():
                ans[key] += j
            else:
                ans[key] = j
    ikasamaDic[index] = ans
    return ans


win = 0
lose = 0
draw = 0

pattern = getPattern(0)
ikasama = getIkasamaPattern(0)

for i in pattern.keys():
    wCount = sum([v for j, v in ikasama.items() if j < i])
    lCount = sum([v for j, v in ikasama.items() if j > i])
    dCount = sum([v for j, v in ikasama.items() if j == i])
    win += wCount * pattern[i]
    lose += lCount * pattern[i]
    draw += dCount * pattern[i]

ans = lose / (win + lose + draw)
print(ans)
0