結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-15 00:15:46
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 508 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 37,504 KB
最終ジャッジ日時 2024-04-27 20:41:46
合計ジャッジ時間 4,045 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
12,160 KB
testcase_01 AC 72 ms
12,160 KB
testcase_02 AC 76 ms
12,288 KB
testcase_03 AC 74 ms
12,288 KB
testcase_04 AC 70 ms
12,288 KB
testcase_05 AC 73 ms
12,288 KB
testcase_06 AC 70 ms
12,160 KB
testcase_07 AC 71 ms
12,288 KB
testcase_08 AC 72 ms
12,160 KB
testcase_09 AC 72 ms
12,160 KB
testcase_10 AC 133 ms
20,992 KB
testcase_11 AC 163 ms
22,400 KB
testcase_12 AC 477 ms
37,504 KB
testcase_13 AC 129 ms
18,304 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 157 ms
20,992 KB
testcase_17 WA -
testcase_18 AC 467 ms
37,376 KB
testcase_19 AC 210 ms
21,248 KB
testcase_20 AC 209 ms
28,800 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - m
Syntax OK

ソースコード

diff #

n, m, k = gets.chomp.split.map!(&:to_i)
op, *b = gets.chomp.split
b.map!(&:to_i)

a = [] * n
n.times do
  a << gets.chomp.to_i % k
end

z = 0
if op == '+'
  h = Hash.new(0)
  b.each do |bi|
    h[bi % k] += 1
  end
  a.each do |ai|
    z += h[k - ai]
  end
else
  ha = Hash.new(0)
  hb = Hash.new(0)
  a.each do |ai|
    ha[ai.gcd(k)] += 1
  end
  b.each do |bi|
    hb[bi.gcd(k)] += 1
  end

  ha.map{|ka, va|
    hb.map{|kb, vb|
      if ka * kb % k == 0
        z += va * vb
      end
    }
  }
end
puts z
0