結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー sepa38sepa38
提出日時 2023-04-16 10:26:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 419 ms / 2,000 ms
コード長 550 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 83,072 KB
最終ジャッジ日時 2024-04-20 02:15:14
合計ジャッジ時間 11,556 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 378 ms
64,128 KB
testcase_01 AC 396 ms
82,480 KB
testcase_02 AC 389 ms
73,856 KB
testcase_03 AC 389 ms
72,832 KB
testcase_04 AC 398 ms
82,688 KB
testcase_05 AC 384 ms
67,840 KB
testcase_06 AC 416 ms
81,876 KB
testcase_07 AC 391 ms
76,032 KB
testcase_08 AC 376 ms
76,032 KB
testcase_09 AC 386 ms
75,904 KB
testcase_10 AC 367 ms
64,384 KB
testcase_11 AC 385 ms
64,128 KB
testcase_12 AC 406 ms
82,048 KB
testcase_13 AC 390 ms
81,920 KB
testcase_14 AC 419 ms
83,072 KB
testcase_15 AC 373 ms
64,640 KB
testcase_16 AC 375 ms
64,384 KB
testcase_17 AC 364 ms
64,384 KB
testcase_18 AC 370 ms
64,512 KB
testcase_19 AC 373 ms
64,640 KB
testcase_20 AC 379 ms
64,256 KB
testcase_21 AC 378 ms
64,256 KB
testcase_22 AC 377 ms
64,128 KB
testcase_23 AC 375 ms
64,384 KB
testcase_24 AC 365 ms
64,128 KB
testcase_25 AC 377 ms
64,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def cominit(n, mod):
  global fac, finv
  fac = [1] * n
  finv = [1] * n
  for i in range(2, n):
    fac[i] = (fac[i-1] * i) % mod
    finv[i] = (finv[i-1] * pow(i, mod-2, mod)) % mod

def comb(n, k):
  global mod
  if n < k:
    return 0
  if n < 0 or k < 0:
    return 0
  return (fac[n] * finv[n-k] % mod) * finv[k] % mod

mod = 998244353
cominit(400000, mod)

n, m, a, b = map(int, input().split())
ans = 0
for i in range(m):
  if a * (n - 1) + i > b:
    break
  ans += (m - (a * (n - 1) + i)) * fac[n] * comb(n-1+i-1, i)
  ans %= mod
print(ans)
0