結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2020-02-15 19:41:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 483 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 11,520 KB
実行使用メモリ 30,716 KB
最終ジャッジ日時 2023-08-10 03:15:11
合計ジャッジ時間 4,525 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,148 KB
testcase_01 AC 83 ms
15,020 KB
testcase_02 AC 82 ms
15,144 KB
testcase_03 AC 82 ms
15,124 KB
testcase_04 AC 80 ms
15,084 KB
testcase_05 AC 82 ms
15,052 KB
testcase_06 AC 80 ms
15,252 KB
testcase_07 AC 82 ms
15,084 KB
testcase_08 AC 83 ms
15,240 KB
testcase_09 AC 82 ms
15,248 KB
testcase_10 AC 155 ms
22,388 KB
testcase_11 AC 192 ms
25,080 KB
testcase_12 AC 420 ms
26,112 KB
testcase_13 AC 145 ms
21,088 KB
testcase_14 AC 198 ms
23,420 KB
testcase_15 AC 155 ms
18,608 KB
testcase_16 AC 176 ms
23,372 KB
testcase_17 AC 135 ms
18,252 KB
testcase_18 AC 422 ms
26,280 KB
testcase_19 AC 207 ms
20,820 KB
testcase_20 AC 237 ms
30,716 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 % 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