結果

問題 No.2527 H and W
ユーザー tomeruntomerun
提出日時 2023-11-03 21:34:59
言語 Crystal
(1.11.2)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 759 bytes
コンパイル時間 11,812 ms
コンパイル使用メモリ 291,568 KB
実行使用メモリ 30,040 KB
最終ジャッジ日時 2023-11-03 21:35:22
合計ジャッジ時間 14,217 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
30,040 KB
testcase_01 AC 35 ms
30,040 KB
testcase_02 AC 48 ms
30,040 KB
testcase_03 AC 36 ms
30,040 KB
testcase_04 AC 37 ms
30,040 KB
testcase_05 AC 35 ms
30,040 KB
testcase_06 AC 35 ms
30,040 KB
testcase_07 AC 36 ms
30,040 KB
testcase_08 AC 47 ms
30,040 KB
testcase_09 AC 34 ms
30,040 KB
testcase_10 AC 35 ms
30,040 KB
testcase_11 AC 35 ms
30,040 KB
testcase_12 AC 40 ms
30,040 KB
testcase_13 AC 41 ms
30,040 KB
testcase_14 AC 48 ms
30,040 KB
testcase_15 AC 35 ms
30,040 KB
testcase_16 AC 46 ms
30,040 KB
testcase_17 AC 47 ms
30,040 KB
testcase_18 AC 51 ms
30,040 KB
testcase_19 AC 41 ms
30,040 KB
testcase_20 AC 43 ms
30,040 KB
testcase_21 AC 46 ms
30,040 KB
testcase_22 AC 48 ms
30,040 KB
testcase_23 AC 50 ms
30,040 KB
testcase_24 AC 43 ms
30,040 KB
testcase_25 AC 34 ms
30,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD  = 998244353i64
FACT = [1i64]
1000001.times do |i|
  FACT << FACT[i] * (i + 1) % MOD
end
FACT_INV = Array.new(FACT.size, 0i64)
FACT_INV[-1] = inv(FACT[-1])
(FACT_INV.size - 2).downto(0) do |i|
  FACT_INV[i] = FACT_INV[i + 1] * (i + 1) % MOD
end

def binom(n, k)
  FACT[n] * FACT_INV[k] % MOD * FACT_INV[n - k] % MOD
end

def inv(v)
  pow(v, MOD - 2)
end

def pow(v, p)
  ret = 1i64
  while p > 0
    if (p & 1i64) != 0
      ret *= v
      ret %= MOD
    end
    v *= v
    v %= MOD
    p >>= 1
  end
  ret
end

h, w, k = read_line.split.map(&.to_i64)
c = h * w - k
ans = 0i64
0.upto(h) do |i|
  rest = c - (w * i)
  break if rest < 0
  if rest % (h - i) == 0
    u = rest // (h - i)
    ans += binom(h, i) * binom(w, u)
    ans %= MOD
  end
end
puts ans
0