結果

問題 No.1253 雀見椪
ユーザー yuruhiyayuruhiya
提出日時 2020-10-11 10:48:43
言語 Crystal
(1.11.2)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,688 bytes
コンパイル時間 19,802 ms
コンパイル使用メモリ 256,124 KB
実行使用メモリ 5,176 KB
最終ジャッジ日時 2023-09-13 12:09:50
合計ジャッジ時間 22,387 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,480 KB
testcase_02 AC 3 ms
4,472 KB
testcase_03 AC 8 ms
4,832 KB
testcase_04 AC 75 ms
5,088 KB
testcase_05 AC 75 ms
5,132 KB
testcase_06 AC 74 ms
5,176 KB
testcase_07 AC 75 ms
5,108 KB
testcase_08 AC 75 ms
5,044 KB
testcase_09 AC 76 ms
4,992 KB
testcase_10 AC 76 ms
5,052 KB
testcase_11 AC 75 ms
5,136 KB
testcase_12 AC 75 ms
5,048 KB
testcase_13 AC 76 ms
4,920 KB
testcase_14 AC 3 ms
4,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

struct ModInt
  @@MOD = 1_000_000_007i64

  def self.mod
    @@MOD
  end

  def self.zero
    ModInt.new(0)
  end

  def initialize(n)
    @n = n.to_i64 % @@MOD
  end

  getter n : Int64

  def + : self
    self
  end

  def - : self
    ModInt.new(n != 0 ? @@MOD - @n : 0)
  end

  def +(m)
    ModInt.new(@n + m.to_i64 % @@MOD)
  end

  def -(m)
    ModInt.new(@n - m.to_i64 % @@MOD)
  end

  def *(m)
    ModInt.new(@n * m.to_i64 % @@MOD)
  end

  def /(m)
    raise DivisionByZeroError.new if m == 0
    a, b, u, v = m.to_i64, @@MOD, 1i64, 0i64
    while b != 0
      t = a // b
      a -= t * b
      a, b = b, a
      u -= t * v
      u, v = v, u
    end
    ModInt.new(@n * u)
  end

  def //(m)
    self / m
  end

  def **(m : Int)
    t, res = self, ModInt.new(1)
    while m > 0
      res *= t if m.odd?
      t *= t
      m >>= 1
    end
    res
  end

  def ==(m)
    @n == m.to_i64
  end

  def !=(m)
    @n != m.to_i64
  end

  def succ
    self + 1
  end

  def pred
    self - 1
  end

  def to_i64 : Int64
    @n
  end

  delegate to_s, to: @n
  delegate inspect, to: @n
end

struct Int
  def to_mint : ModInt
    ModInt.new(self)
  end
end

read_line.to_i.times do
  input = read_line.split.map(&.to_i64)
  n = input.shift
  a = (1..3).map {
    x, y = input.shift(2)
    x.to_mint / y
  }

  x0 = a[0] ** n
  x1 = a[1] ** n
  x2 = a[2] ** n
  y0 = (a[0] + a[1]) ** n - (x0 + x1)
  y1 = (a[0] + a[2]) ** n - (x0 + x2)
  y2 = (a[1] + a[2]) ** n - (x1 + x2)
  z = 1.to_mint - (x0 + x1 + x2) - (y0 + y1 + y2)
  puts x0 + x1 + x2 + z
end
0