結果

問題 No.1552 Simple Dice Game
ユーザー H3PO4H3PO4
提出日時 2022-10-15 09:53:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,140 ms / 2,500 ms
コード長 520 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 82,040 KB
最終ジャッジ日時 2023-09-09 02:19:59
合計ジャッジ時間 15,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,256 KB
testcase_01 AC 73 ms
71,408 KB
testcase_02 AC 71 ms
71,376 KB
testcase_03 AC 1,140 ms
81,776 KB
testcase_04 AC 72 ms
71,484 KB
testcase_05 AC 72 ms
71,248 KB
testcase_06 AC 72 ms
71,612 KB
testcase_07 AC 72 ms
71,136 KB
testcase_08 AC 71 ms
71,452 KB
testcase_09 AC 873 ms
81,148 KB
testcase_10 AC 1,020 ms
81,216 KB
testcase_11 AC 1,032 ms
81,540 KB
testcase_12 AC 316 ms
78,100 KB
testcase_13 AC 867 ms
80,876 KB
testcase_14 AC 568 ms
79,828 KB
testcase_15 AC 656 ms
80,388 KB
testcase_16 AC 151 ms
77,248 KB
testcase_17 AC 201 ms
77,520 KB
testcase_18 AC 841 ms
80,892 KB
testcase_19 AC 1,116 ms
82,040 KB
testcase_20 AC 1,126 ms
81,656 KB
testcase_21 AC 1,116 ms
81,644 KB
testcase_22 AC 1,109 ms
81,904 KB
testcase_23 AC 1,130 ms
81,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
MOD = 998244353

pow_table = [pow(k, N - 1, MOD) for k in range(M + 1)]


def tri(x):
    return x * (x + 1) // 2


def fix_max(k):
    return k * N * (tri(k) * pow_table[k] - tri(k - 1) * pow_table[k - 1]) % MOD


def fix_min(k):
    return k * N * ((tri(M) - tri(k - 1)) * pow_table[M - k + 1] - (tri(M) - tri(k)) * pow_table[M - k]) % MOD


ans = 0
for k in range(1, M + 1):
    # print(k, fix_max(k), fix_min(k))
    ans += fix_max(k)
    ans -= fix_min(k)
    ans %= MOD
print(ans)
0