結果

問題 No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!)
ユーザー tomerun
提出日時 2024-02-23 23:20:01
言語 Crystal
(1.14.0)
結果
WA  
実行時間 -
コード長 733 bytes
コンパイル時間 13,652 ms
コンパイル使用メモリ 294,640 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2024-09-29 08:51:13
合計ジャッジ時間 19,198 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 69
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353i64

read_line.to_i.times do
  puts solve()
end

def solve
  n, m = read_line.split.map(&.to_i64)
  x = read_line.split.map(&.to_i64)
  if !x.includes?(-1)
    ans = n
    sum = 0
    n.times do |i|
      sum += x[i]
      sum %= m
      ans -= 1 if sum == 0
    end
    return sum == 0 ? ans : 0
  end
  ans = 0i64
  comb = 1i64
  sum = 0i64
  i = 0
  while x[i] != -1
    sum += x[i]
    sum %= m
    if sum == 0
      ans += 1
    end
    i += 1
  end
  ans += comb
  ans %= MOD
  i += 1
  while i < n
    if x[i] == -1
      comb *= m
      comb %= MOD
      ans = ans * m + comb
      ans %= MOD
    else
      ans += comb
      ans %= MOD
    end
    i += 1
  end
  return (comb * n % MOD - ans + MOD) % MOD
end
0