結果

問題 No.2679 MODice
ユーザー Ekiben542Ekiben542
提出日時 2024-03-20 21:11:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 766 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 584,208 KB
最終ジャッジ日時 2024-03-20 21:11:34
合計ジャッジ時間 4,225 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
16,788 KB
testcase_01 AC 35 ms
9,984 KB
testcase_02 AC 32 ms
9,984 KB
testcase_03 AC 37 ms
9,984 KB
testcase_04 AC 33 ms
9,984 KB
testcase_05 AC 34 ms
9,984 KB
testcase_06 MLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def dice_remainder_probability(N, K):
    dp = [[0 for _ in range(6*N+1)] for _ in range(N+1)]
    dp[0][0] = 1

    # DP
    for i in range(N):
        for j in range(6*i+1):
            for k in range(1, 7):
                dp[i+1][j+k] += dp[i][j]

    total = 0
    for i in range(K, 6*N+1, 6):
        total += dp[N][i]

    return total, 6**N  

def mod_inverse(a, m):
    g, x, y = extended_gcd(a, m)
    if g != 1:
        raise Exception('M')
    else:
        return x % m

def extended_gcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, x, y = extended_gcd(b % a, a)
        return g, y - (b // a) * x, x

N, K = map(int, input().split())
P, Q = dice_remainder_probability(N, K)
R = (P * mod_inverse(Q, 998244353)) % 998244353
print(R)
0