結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー simansiman
提出日時 2020-02-15 03:49:55
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 640 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 11,572 KB
実行使用メモリ 31,216 KB
最終ジャッジ日時 2023-08-10 03:08:44
合計ジャッジ時間 4,781 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,032 KB
testcase_01 AC 76 ms
15,076 KB
testcase_02 AC 75 ms
15,124 KB
testcase_03 AC 76 ms
15,184 KB
testcase_04 AC 77 ms
15,264 KB
testcase_05 AC 76 ms
15,176 KB
testcase_06 AC 75 ms
15,308 KB
testcase_07 AC 77 ms
15,220 KB
testcase_08 AC 79 ms
15,212 KB
testcase_09 AC 78 ms
15,216 KB
testcase_10 AC 185 ms
23,448 KB
testcase_11 AC 195 ms
24,808 KB
testcase_12 AC 446 ms
31,136 KB
testcase_13 AC 153 ms
20,756 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 215 ms
23,076 KB
testcase_17 WA -
testcase_18 AC 453 ms
31,216 KB
testcase_19 AC 215 ms
22,880 KB
testcase_20 AC 324 ms
30,888 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
gcd_counter_a = Hash.new(0)
gcd_counter_b = Hash.new(0)
mod_counter = Hash.new(0)

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

A.each do |a|
  gcd_counter_a[a.gcd(K)] += 1
end

if op == '+'
  A.each do |a|
    if op == '+'
      ans += mod_counter[K - a % K]
    end
  end
else
  gcd_counter_a.each do |a, m|
    gcd_counter_b.each do |b, n|
      next if (a * b) % K != 0

      ans += m * n
    end
  end
end

puts ans
0