結果

問題 No.58 イカサマなサイコロ
ユーザー tobusakanatobusakana
提出日時 2022-11-05 15:13:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 771 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 76,420 KB
最終ジャッジ日時 2023-09-26 14:03:07
合計ジャッジ時間 1,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,456 KB
testcase_01 AC 83 ms
76,420 KB
testcase_02 AC 70 ms
71,256 KB
testcase_03 AC 71 ms
71,608 KB
testcase_04 AC 73 ms
71,200 KB
testcase_05 AC 75 ms
75,544 KB
testcase_06 AC 78 ms
75,544 KB
testcase_07 AC 71 ms
71,432 KB
testcase_08 AC 73 ms
71,016 KB
testcase_09 AC 76 ms
75,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
K = int(input())

M = 6 * N # 出しうる最大の値

edited = [4,4,5,5,6,6]
normal = [1,2,3,4,5,6]

def f(X):
  x = [0] * (M + 1)
  x[0] = 1
  dice = normal
  for i in range(N):
    new_x = [0] * (M + 1)
    for j in range(M + 1):
      if x[j] == 0:
        continue
      if i >= (N - K): # normalを(N - K)回以上使っていたら、Xに切り替える
        dice = X
#      print("dice",dice,"を振る")
      for k in range(6):
#        print(j + dice[k],"に",x[j] / 6,"の確率で到達")
        new_x[j + dice[k]] += x[j] / 6
#        print("new_x",new_x)
    x = new_x
  return x
  
jiro = f(normal)
taro = f(edited)

ans = 0
jiro_lose = 0
for i in range(len(taro)):
  ans += taro[i] * jiro_lose
  jiro_lose += jiro[i]
  
print(ans)  
0