結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
12,416 KB
testcase_01 AC 75 ms
12,288 KB
testcase_02 AC 76 ms
12,416 KB
testcase_03 AC 76 ms
12,288 KB
testcase_04 AC 79 ms
12,160 KB
testcase_05 AC 75 ms
12,160 KB
testcase_06 AC 78 ms
12,288 KB
testcase_07 AC 77 ms
12,160 KB
testcase_08 AC 78 ms
12,160 KB
testcase_09 AC 75 ms
12,160 KB
testcase_10 AC 144 ms
20,096 KB
testcase_11 AC 177 ms
22,272 KB
testcase_12 AC 406 ms
23,808 KB
testcase_13 AC 138 ms
18,944 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 164 ms
21,632 KB
testcase_17 WA -
testcase_18 AC 420 ms
23,936 KB
testcase_19 AC 198 ms
18,560 KB
testcase_20 AC 210 ms
29,312 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[K - (a % K)] += 1}
  puts B.inject(0){|s,b| s + Amod[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