結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー simansiman
提出日時 2020-02-14 22:57:52
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 556 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 34,176 KB
最終ジャッジ日時 2024-04-27 20:05:19
合計ジャッジ時間 4,057 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
12,160 KB
testcase_01 AC 80 ms
12,032 KB
testcase_02 WA -
testcase_03 AC 80 ms
12,288 KB
testcase_04 WA -
testcase_05 AC 80 ms
12,032 KB
testcase_06 RE -
testcase_07 WA -
testcase_08 AC 75 ms
12,032 KB
testcase_09 AC 78 ms
12,288 KB
testcase_10 AC 168 ms
23,424 KB
testcase_11 RE -
testcase_12 WA -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 173 ms
23,296 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 245 ms
34,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Integer
  def mod_inverse(mod)
    self.pow(mod - 2, mod)
  end
end

N, M, K = gets.split.map(&:to_i)
op, *B = gets.chomp.split
B.map!(&:to_i)
A = N.times.map { gets.to_i }
ans = 0
mod_counter = Hash.new(0)
mod_counter_plus = Hash.new(0)

B.each do |b|
  mod_counter[b % (K - 1)] += 1
  mod_counter_plus[b % K] += 1
end

A.each do |a|
  if op == '+'
    mk = a % K
    ans += mod_counter_plus[K - mk]
  else
    if a % K == 0
      ans += M
    else
      ans += mod_counter[1] + mod_counter[K - 1 - a.mod_inverse(K - 1)]
    end
  end
end

puts ans
0