結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2020-02-15 19:30:23
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 482 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 29,184 KB
最終ジャッジ日時 2024-04-27 20:49:25
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 86 ms
12,288 KB
testcase_02 AC 90 ms
11,904 KB
testcase_03 WA -
testcase_04 AC 86 ms
12,160 KB
testcase_05 AC 86 ms
12,160 KB
testcase_06 AC 88 ms
12,032 KB
testcase_07 AC 93 ms
12,032 KB
testcase_08 AC 93 ms
12,032 KB
testcase_09 AC 91 ms
12,160 KB
testcase_10 WA -
testcase_11 AC 212 ms
21,888 KB
testcase_12 AC 474 ms
23,680 KB
testcase_13 AC 157 ms
18,432 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 461 ms
23,808 KB
testcase_19 AC 224 ms
18,560 KB
testcase_20 AC 248 ms
29,184 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M, K = gets.split.map(&:to_i)
op, *cols = gets.split
op = op.to_sym
B = cols.map(&:to_i)
A = N.times.map{ gets.to_i }

if op == :+
  Amod = Hash.new(0)
  A.each{|a| Amod[a] += 1}
  puts B.inject(0){|s,b| s + Amod[(K - b) % K] }
else
  Agcd = Hash.new(0)
  Bgcd = Hash.new(0)
  A.each{|a| Agcd[a.gcd(K)] += 1 }
  B.each{|b| Bgcd[b.gcd(K)] += 1 }
  ans = 0

  Agcd.each do |ag, ac|
    Bgcd.each do |bg, bc|
      ans += ac * bc if (ag * bg) % K == 0
    end
  end
  puts ans
end

0