結果
| 問題 |
No.1856 Mex Sum 2
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:58:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,034 bytes |
| コンパイル時間 | 207 ms |
| コンパイル使用メモリ | 82,156 KB |
| 実行使用メモリ | 109,648 KB |
| 最終ジャッジ日時 | 2025-03-20 21:00:17 |
| 合計ジャッジ時間 | 26,022 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 WA * 19 RE * 13 |
ソースコード
MOD = 998244353
def main():
import sys
N, M = map(int, sys.stdin.readline().split())
max_x = min(N + 1, M + 1)
# Precompute combinations C[x][s]
C = [[0] * (2001) for _ in range(2001)]
C[0][0] = 1
for x in range(1, 2001):
C[x][0] = 1
for s in range(1, x+1):
C[x][s] = (C[x-1][s-1] + C[x-1][s]) % MOD
ans = 0
for x in range(1, max_x + 1):
if x - 1 > M:
continue
res = 0
for s in range(0, x+1):
sign = (-1) ** (x - s)
comb = C[x][s]
if x <= M:
base = (s + 2 * M - x + 1) % MOD
else:
base = (s + x + 1) % MOD
# Compute base^N mod MOD
pow_val = pow(base, N, MOD)
term = comb * pow_val
term %= MOD
if (x - s) % 2 == 1:
term = (-term) % MOD
res = (res + term) % MOD
ans = (ans + x * res) % MOD
print(ans % MOD)
if __name__ == "__main__":
main()
lam6er