結果

問題 No.2084 Mex Subset For All Sequences
ユーザー qwewe
提出日時 2025-04-24 12:20:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,137 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 82,972 KB
実行使用メモリ 65,160 KB
最終ジャッジ日時 2025-04-24 12:22:43
合計ジャッジ時間 3,562 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def main():
    import sys
    N, M = map(int, sys.stdin.readline().split())
    
    if M == 0:
        print(0)
        return
    
    max_n = M + 1
    fact = [1] * (max_n + 1)
    for i in range(1, max_n + 1):
        fact[i] = fact[i-1] * i % MOD
    
    inv_fact = [1] * (max_n + 1)
    inv_fact[max_n] = pow(fact[max_n], MOD-2, MOD)
    for i in range(max_n - 1, -1, -1):
        inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
    
    def comb(n, k):
        if k < 0 or k > n:
            return 0
        return fact[n] * inv_fact[k] % MOD * inv_fact[n - k] % MOD
    
    part1 = pow(M, N + 1, MOD) * (pow(2, N, MOD) - 1) % MOD
    
    sum_terms = 0
    for s in range(1, M + 1):
        s_plus_1 = s + 1
        c = comb(M + 1, s_plus_1)
        base = (2 * M - s) % MOD
        pow_base = pow(base, N, MOD)
        pow_MN = pow(M, N, MOD)
        diff = (pow_base - pow_MN) % MOD
        term = c * diff % MOD
        if s % 2 == 1:
            term = (-term) % MOD
        sum_terms = (sum_terms + term) % MOD
    
    total = (part1 + sum_terms) % MOD
    print(total)

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