結果
| 問題 |
No.2084 Mex Subset For All Sequences
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:58:04 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,586 bytes |
| コンパイル時間 | 235 ms |
| コンパイル使用メモリ | 82,776 KB |
| 実行使用メモリ | 76,844 KB |
| 最終ジャッジ日時 | 2025-03-20 20:58:28 |
| 合計ジャッジ時間 | 4,125 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 TLE * 1 -- * 19 |
ソースコード
MOD = 998244353
def main():
import sys
N, M = map(int, sys.stdin.readline().split())
if M == 0:
print(0)
return
max_fact = max(M, N)
fact = [1] * (max_fact + 2)
for i in range(1, max_fact + 1):
fact[i] = fact[i-1] * i % MOD
inv_fact = [1] * (max_fact + 2)
inv_fact[max_fact] = pow(fact[max_fact], MOD-2, MOD)
for i in range(max_fact -1, -1, -1):
inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
def comb(v, s):
if s <0 or s > v:
return 0
return fact[v] * inv_fact[s] % MOD * inv_fact[v - s] % MOD
a_lt = 2 * M -1
pow_lt = [pow(a_lt - s, N, MOD) for s in range(M)]
a_eq = 2 * M
pow_eq = [pow(a_eq - s, N, MOD) for s in range(M +1)]
ans = 0
for v in range(1, M+1):
if v > N:
res =0
else:
if v < M:
a = a_lt
res =0
for s in range(0, v+1):
c = comb(v, s)
if s %2 ==1:
c = (-c) % MOD
term = c * pow_lt[s]
res = (res + term) % MOD
elif v == M:
a = a_eq
res =0
for s in range(0, v+1):
c = comb(v, s)
if s %2 ==1:
c = (-c) % MOD
term = c * pow_eq[s]
res = (res + term) % MOD
else:
res =0
ans = (ans + res * v) % MOD
print(ans % MOD)
if __name__ == '__main__':
main()
lam6er