結果

問題 No.2679 MODice
ユーザー ThetaTheta
提出日時 2024-04-18 17:20:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 78,316 KB
最終ジャッジ日時 2024-04-18 17:20:54
合計ジャッジ時間 2,046 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,304 KB
testcase_01 AC 43 ms
56,424 KB
testcase_02 AC 41 ms
54,704 KB
testcase_03 AC 42 ms
55,224 KB
testcase_04 AC 43 ms
55,552 KB
testcase_05 AC 42 ms
55,820 KB
testcase_06 AC 86 ms
77,320 KB
testcase_07 AC 91 ms
76,820 KB
testcase_08 AC 83 ms
78,316 KB
testcase_09 AC 61 ms
70,136 KB
testcase_10 AC 60 ms
70,296 KB
testcase_11 AC 63 ms
70,988 KB
testcase_12 AC 90 ms
78,144 KB
testcase_13 AC 65 ms
71,968 KB
testcase_14 AC 80 ms
77,380 KB
testcase_15 AC 65 ms
70,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cache
MOD = 998244353


@cache
def calc_possibility(n: int, k: int) -> int:
    if n == 1:
        return pow(6, MOD - 2, MOD)

    if n % 2 == 0:
        return sum(
            (calc_possibility(
                n //
                2,
                idx) *
             calc_possibility(
                n //
                2,
                (k -
                 idx) %
                6)) % MOD for idx in range(6)) % MOD

    if n % 2 == 1:
        return ((sum(calc_possibility(n - 1, idx) %
                MOD for idx in range(6)) % MOD) * pow(6, MOD - 2, MOD)) % MOD


def main():
    N, K = map(int, input().split())

    # N個の出目の総和を6で割った余りがKとなる確率
    # N/2個の出目の総和を6で割った余りがjとなる確率*(K-j)%6となる確率
    print(calc_possibility(N, K))


if __name__ == "__main__":
    main()
0