結果

問題 No.1186 長方形の敷き詰め
ユーザー simansiman
提出日時 2020-08-25 03:16:11
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 36,836 KB
最終ジャッジ日時 2024-04-24 04:07:01
合計ジャッジ時間 8,402 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
12,288 KB
testcase_01 AC 99 ms
12,160 KB
testcase_02 AC 575 ms
36,712 KB
testcase_03 AC 92 ms
12,288 KB
testcase_04 AC 93 ms
12,160 KB
testcase_05 AC 94 ms
12,288 KB
testcase_06 AC 93 ms
12,032 KB
testcase_07 AC 95 ms
12,032 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 96 ms
12,288 KB
testcase_12 AC 96 ms
12,288 KB
testcase_13 AC 95 ms
12,160 KB
testcase_14 AC 95 ms
12,160 KB
testcase_15 AC 93 ms
12,160 KB
testcase_16 AC 92 ms
12,160 KB
testcase_17 AC 222 ms
24,064 KB
testcase_18 AC 370 ms
28,664 KB
testcase_19 AC 431 ms
31,332 KB
testcase_20 AC 470 ms
35,712 KB
testcase_21 AC 360 ms
30,976 KB
testcase_22 AC 705 ms
36,836 KB
testcase_23 AC 331 ms
30,208 KB
testcase_24 AC 478 ms
34,944 KB
testcase_25 AC 326 ms
29,952 KB
testcase_26 AC 364 ms
27,756 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class ModCombination
  attr_reader :fac, :inv, :finv, :mod

  MOD = 10 ** 9 + 7

  def initialize(n, mod: MOD)
    @mod = mod
    @fac = [1, 1]
    @inv = [1, 1]
    @finv = [1, 1]

    (2..n).each do |i|
      @fac[i] = fac[i - 1] * i % mod
      @inv[i] = mod - inv[mod % i] * (mod / i) % mod
      @finv[i] = finv[i - 1] * inv[i] % mod
    end
  end

  def combination(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0

    fac[n] * (finv[k] * finv[n - k] % mod) % mod
  end
end

MOD = 998244353
N, M = gets.split.map(&:to_i)
mc = ModCombination.new(M + 1, mod: MOD)
ans = 0

0.upto(M / N) do |i|
  n = M - N * i + i

  ans += mc.combination(n, i)
  ans %= MOD
end

puts ans
0