結果

問題 No.1310 量子アニーリング
ユーザー simansiman
提出日時 2021-06-23 02:03:55
言語 Ruby
(3.3.0)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 871 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 11,256 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2023-09-06 02:43:24
合計ジャッジ時間 5,234 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,184 KB
testcase_01 AC 79 ms
15,312 KB
testcase_02 AC 83 ms
15,072 KB
testcase_03 AC 86 ms
15,204 KB
testcase_04 AC 82 ms
15,236 KB
testcase_05 AC 82 ms
15,156 KB
testcase_06 AC 82 ms
15,120 KB
testcase_07 AC 82 ms
15,288 KB
testcase_08 AC 81 ms
15,260 KB
testcase_09 AC 82 ms
15,108 KB
testcase_10 AC 82 ms
15,172 KB
testcase_11 AC 79 ms
15,072 KB
testcase_12 AC 82 ms
15,512 KB
testcase_13 AC 115 ms
17,064 KB
testcase_14 AC 131 ms
17,668 KB
testcase_15 AC 145 ms
17,572 KB
testcase_16 AC 148 ms
17,784 KB
testcase_17 AC 182 ms
19,092 KB
testcase_18 AC 218 ms
19,984 KB
testcase_19 AC 138 ms
17,668 KB
testcase_20 AC 104 ms
16,564 KB
testcase_21 AC 95 ms
16,044 KB
testcase_22 AC 221 ms
20,096 KB
testcase_23 AC 115 ms
16,892 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class ModInteger
  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

  def permutation(n, k = n)
    return 0 if n < k
    return 0 if n < 0 || k < 0

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

  def repeated_combination(n, k)
    combination(n + k - 1, k)
  end
end

N = gets.to_i
MOD = 998_244_353
mi = ModInteger.new(N, mod: MOD)
ans = 0

0.step(N, 2) do |k|
  ans += 2 * mi.combination(N, k) * 2.pow((N - 2 * k).abs, MOD)
  ans %= MOD
end

puts ans
0