結果
問題 | No.573 a^2[i] = a[i] |
ユーザー |
![]() |
提出日時 | 2020-10-17 11:49:34 |
言語 | Crystal (1.14.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 2,100 bytes |
コンパイル時間 | 11,486 ms |
コンパイル使用メモリ | 295,316 KB |
実行使用メモリ | 9,984 KB |
最終ジャッジ日時 | 2024-06-30 21:22:57 |
合計ジャッジ時間 | 13,375 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
ソースコード
lib Cfun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64endclass Stringdef to_i64C.strtoll(self, nil, 10)endendstruct ModInt@@MOD = 1_000_000_007i64def self.mod@@MODenddef self.zeroModInt.new(0)enddef initialize(n)@n = n.to_i64 % @@MODendgetter n : Int64def + : selfselfenddef - : selfModInt.new(n != 0 ? @@MOD - @n : 0)enddef +(m)ModInt.new(@n + m.to_i64 % @@MOD)enddef -(m)ModInt.new(@n - m.to_i64 % @@MOD)enddef *(m)ModInt.new(@n * m.to_i64 % @@MOD)enddef /(m)raise DivisionByZeroError.new if m == 0a, b, u, v = m.to_i64, @@MOD, 1i64, 0i64while b != 0t = a // ba -= t * ba, b = b, au -= t * vu, v = v, uendModInt.new(@n * u)enddef //(m)self / menddef **(m : Int)t, res = self, ModInt.new(1)while m > 0res *= t if m.odd?t *= tm >>= 1endresenddef ==(m)@n == m.to_i64enddef !=(m)@n != m.to_i64enddef succself + 1enddef predself - 1enddef to_i64 : Int64@nenddelegate to_s, to: @ndelegate inspect, to: @nendstruct Intdef to_mint : ModIntModInt.new(self)endendclass Comb(T)def initialize(@Max = 300009)@fac = Array(T).new(@Max, T.zero)@finv = Array(T).new(@Max, T.zero)@inv = Array(T).new(@Max, T.zero)@fac[0] = @fac[1] = T.new(1)@finv[0] = @finv[1] = T.new(1)@inv[1] = T.new(1)(2...@Max).each do |i|@fac[i] = @fac[i - 1] * i@inv[i] = -@inv[T.mod % i] * (T.mod / i)@finv[i] = @finv[i - 1] * @inv[i]endenddef p(n, r)(n < r || n < 0 || r < 0) ? 0 : @fac[n] * @finv[n - r]enddef c(n, r)(n < r || n < 0 || r < 0) ? 0 : @fac[n] * @finv[r] * @finv[n - r]enddef h(n, r)(n < 0 || r < 0) ? 0 : r == 0 ? 1 : c(n + r - 1, r)enddef fact(n)@fac[n]endendn = read_line.to_icombi = Comb(ModInt).newputs (0..n).sum { |i|i.to_mint ** (n - i) * combi.c(n, i)}