結果

問題 No.1299 Random Array Score
ユーザー yuruhiyayuruhiya
提出日時 2020-11-27 21:47:25
言語 Crystal
(1.11.2)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 18,528 ms
コンパイル使用メモリ 255,476 KB
実行使用メモリ 21,252 KB
最終ジャッジ日時 2023-09-13 12:44:21
合計ジャッジ時間 21,369 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 32 ms
18,244 KB
testcase_04 AC 29 ms
15,912 KB
testcase_05 AC 24 ms
14,332 KB
testcase_06 AC 22 ms
15,404 KB
testcase_07 AC 24 ms
14,496 KB
testcase_08 AC 30 ms
17,208 KB
testcase_09 AC 3 ms
4,668 KB
testcase_10 AC 14 ms
9,408 KB
testcase_11 AC 5 ms
5,636 KB
testcase_12 AC 22 ms
14,292 KB
testcase_13 AC 29 ms
15,980 KB
testcase_14 AC 23 ms
14,548 KB
testcase_15 AC 24 ms
14,544 KB
testcase_16 AC 23 ms
15,932 KB
testcase_17 AC 6 ms
6,224 KB
testcase_18 AC 15 ms
9,696 KB
testcase_19 AC 17 ms
10,216 KB
testcase_20 AC 10 ms
7,916 KB
testcase_21 AC 3 ms
4,612 KB
testcase_22 AC 7 ms
6,384 KB
testcase_23 AC 23 ms
14,552 KB
testcase_24 AC 25 ms
14,516 KB
testcase_25 AC 22 ms
14,396 KB
testcase_26 AC 3 ms
4,440 KB
testcase_27 AC 8 ms
6,820 KB
testcase_28 AC 6 ms
5,728 KB
testcase_29 AC 8 ms
7,212 KB
testcase_30 AC 20 ms
13,028 KB
testcase_31 AC 9 ms
7,096 KB
testcase_32 AC 29 ms
16,500 KB
testcase_33 AC 31 ms
21,048 KB
testcase_34 AC 22 ms
14,720 KB
testcase_35 AC 31 ms
21,252 KB
testcase_36 AC 22 ms
14,648 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 = 998244353i64

  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) % @@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

class String
  def to_mint : ModInt
    ModInt.new(self)
  end
end

n, k = read_line.split.map(&.to_i64)
a = read_line.split.map(&.to_mint)
puts a.sum * ModInt.new(2) ** k
0