結果

問題 No.1258 コインゲーム
ユーザー yuruhiyayuruhiya
提出日時 2020-10-16 22:11:34
言語 Crystal
(1.11.2)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 20,157 ms
コンパイル使用メモリ 250,932 KB
実行使用メモリ 5,280 KB
最終ジャッジ日時 2023-09-13 12:15:53
合計ジャッジ時間 33,047 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
5,100 KB
testcase_01 AC 61 ms
5,080 KB
testcase_02 AC 25 ms
5,124 KB
testcase_03 AC 192 ms
5,096 KB
testcase_04 AC 221 ms
5,028 KB
testcase_05 AC 39 ms
5,184 KB
testcase_06 AC 164 ms
5,052 KB
testcase_07 AC 19 ms
5,212 KB
testcase_08 AC 16 ms
5,040 KB
testcase_09 AC 82 ms
5,048 KB
testcase_10 AC 193 ms
5,184 KB
testcase_11 AC 216 ms
5,124 KB
testcase_12 AC 161 ms
5,116 KB
testcase_13 AC 51 ms
5,168 KB
testcase_14 AC 18 ms
5,084 KB
testcase_15 AC 190 ms
5,236 KB
testcase_16 AC 40 ms
5,036 KB
testcase_17 AC 219 ms
5,124 KB
testcase_18 AC 80 ms
5,056 KB
testcase_19 AC 77 ms
5,052 KB
testcase_20 AC 157 ms
5,016 KB
testcase_21 AC 202 ms
5,120 KB
testcase_22 AC 140 ms
5,056 KB
testcase_23 AC 106 ms
5,056 KB
testcase_24 AC 41 ms
5,148 KB
testcase_25 AC 98 ms
5,236 KB
testcase_26 AC 82 ms
5,064 KB
testcase_27 AC 194 ms
5,100 KB
testcase_28 AC 53 ms
5,040 KB
testcase_29 AC 85 ms
5,124 KB
testcase_30 AC 246 ms
5,124 KB
testcase_31 AC 62 ms
5,104 KB
testcase_32 AC 29 ms
5,204 KB
testcase_33 AC 170 ms
5,080 KB
testcase_34 AC 202 ms
5,156 KB
testcase_35 AC 72 ms
5,204 KB
testcase_36 AC 202 ms
4,980 KB
testcase_37 AC 77 ms
5,080 KB
testcase_38 AC 188 ms
5,016 KB
testcase_39 AC 55 ms
5,124 KB
testcase_40 AC 251 ms
5,056 KB
testcase_41 AC 252 ms
5,096 KB
testcase_42 AC 254 ms
5,076 KB
testcase_43 AC 248 ms
5,168 KB
testcase_44 AC 245 ms
5,280 KB
testcase_45 AC 249 ms
5,128 KB
testcase_46 AC 247 ms
5,096 KB
testcase_47 AC 247 ms
5,052 KB
testcase_48 AC 251 ms
5,192 KB
testcase_49 AC 255 ms
5,048 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
  n, m, x = read_line.split.map(&.to_i)
  sum_all = (m + 1).to_mint ** n
  sum_even = ((1 - m).to_mint ** n + (1 + m).to_mint**n) / 2
  if x == 0
    puts sum_even
  else
    puts sum_all - sum_even
  end
end
0