結果

問題 No.1299 Random Array Score
ユーザー maguroflymagurofly
提出日時 2020-11-27 22:40:53
言語 Ruby
(3.3.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 3,154 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 11,696 KB
実行使用メモリ 28,868 KB
最終ジャッジ日時 2023-10-09 20:44:39
合計ジャッジ時間 6,772 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,332 KB
testcase_01 AC 83 ms
15,268 KB
testcase_02 AC 85 ms
15,156 KB
testcase_03 AC 162 ms
28,572 KB
testcase_04 AC 161 ms
28,316 KB
testcase_05 AC 144 ms
25,088 KB
testcase_06 AC 139 ms
24,324 KB
testcase_07 AC 143 ms
24,440 KB
testcase_08 AC 160 ms
27,856 KB
testcase_09 AC 87 ms
15,412 KB
testcase_10 AC 114 ms
20,080 KB
testcase_11 AC 92 ms
16,136 KB
testcase_12 AC 137 ms
23,744 KB
testcase_13 AC 158 ms
27,560 KB
testcase_14 AC 141 ms
24,132 KB
testcase_15 AC 141 ms
24,364 KB
testcase_16 AC 138 ms
24,128 KB
testcase_17 AC 96 ms
16,872 KB
testcase_18 AC 116 ms
20,680 KB
testcase_19 AC 128 ms
21,876 KB
testcase_20 AC 107 ms
18,588 KB
testcase_21 AC 86 ms
15,440 KB
testcase_22 AC 98 ms
17,228 KB
testcase_23 AC 138 ms
23,948 KB
testcase_24 AC 142 ms
25,116 KB
testcase_25 AC 136 ms
23,988 KB
testcase_26 AC 85 ms
15,336 KB
testcase_27 AC 100 ms
17,588 KB
testcase_28 AC 92 ms
16,652 KB
testcase_29 AC 101 ms
17,920 KB
testcase_30 AC 135 ms
23,304 KB
testcase_31 AC 101 ms
17,992 KB
testcase_32 AC 155 ms
27,588 KB
testcase_33 AC 162 ms
28,644 KB
testcase_34 AC 153 ms
26,932 KB
testcase_35 AC 164 ms
28,868 KB
testcase_36 AC 153 ms
27,128 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

DEBUG = false
MOD = 998244353
YESNO = %w(Yes No)

def main
  @N, @K = ints
  @A = ints
  sum = @A.sum % MOD
  sum *= 2.pow(@K, MOD)
  puts sum % MOD
end

def int; gets.to_i; end
def ints; gets.split.map &:to_i; end
def float; gets.to_f; end
def floats; gets.split.map &:to_f; end
def array_of(&convert); gets.split.map(&convert); end
def string; gets.chomp; end
def rep(n, &b); Array.new(n, &b); end
def yes; puts YESNO[0]; end
def no; puts YESNO[1]; end
def yesno t; t ? yes : no; end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } }; end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max; end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min; end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax; end
def gcd(*xs); xs.inject(0) { |y, x| y.gcd(x) }; end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w }; end
def debug(x); if DEBUG; STDERR.puts (block_given? ? yield(x) : x).inspect; end; x; end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid; end
def if_debug; yield if DEBUG; end

class Integer
  def div_ceil(y); (self + y - 1) / y; end
  def mod_inv(mod = MOD); pow(mod-2, mod); end
  def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod; end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod }; end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1; end; c; end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block); end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1; end
  def end_close; exclude_end? ? self.end - 1 : self.end; end
  def upper_bound; ac, wa = self.begin, self.end_open; while ac + 1 < wa; wj = (ac + wa) / 2; if yield(wj); ac = wj; else; wa = wj; end; end; ac; end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac > wa + 1; wj = (ac + wa) / 2; if yield(wj); ac = wj; else; wa = wj; end; end; ac; end
end

class Array
  def sorted_uniq; x = nil; xs.filter { |y| c = x === y; x = y; !c }; end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys; end
  def cumdiff; xs = []; inject { |x, y| xs << (d = y - x); d }; end
  def cumfold(range); r = range.end; r -= 1 if range.exclusive_end?; self[r] - self[range.begin-1]; end
end

class UnionFind
  def initialize(size); @p, @r = size.times.to_a, [1] * size; end
  def merge(i, j); k, l = leader(i), leader(j); return if k == l; k, l = l, k if @r[k] < @r[l]; @p[l] = k; @r[k] += @r[l]; end
  def size(i); @r[leader(i)]; end
  def same?(i, j); leader(i) == leader(j); end
  def leader(i); j = i; until i == @p[i]; j, i = i, @p[j] = @p[i]; end; i; end
end

class Factorials
  def initialize(limit, mod = MOD); @fac, @fin, @inv, @mod = [1, 1], [1, 1], [nil, 1], mod; (2..limit).each { |i| @fac[i] = @fac[i-1] * i % mod; @inv[i] = mod - @inv[mod % i] * (mod / i) % mod; @fin[i] = @fin[i-1] * @inv[i] % mod }; end
  def fact(n); @fac[n]; end
  def comb(n, k); perm(n, k) * @fin[k] % @mod; end
  def perm(n, k); @fac[n] * @fin[n-k] % @mod; end
end

main
0