結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
12,288 KB
testcase_01 AC 78 ms
12,288 KB
testcase_02 AC 76 ms
12,160 KB
testcase_03 AC 79 ms
12,288 KB
testcase_04 AC 81 ms
12,160 KB
testcase_05 AC 77 ms
12,416 KB
testcase_06 AC 80 ms
12,160 KB
testcase_07 AC 81 ms
12,288 KB
testcase_08 AC 77 ms
12,416 KB
testcase_09 AC 75 ms
12,288 KB
testcase_10 AC 140 ms
20,608 KB
testcase_11 AC 183 ms
18,944 KB
testcase_12 AC 474 ms
37,100 KB
testcase_13 AC 146 ms
17,792 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 161 ms
20,096 KB
testcase_17 WA -
testcase_18 AC 432 ms
37,072 KB
testcase_19 AC 212 ms
21,876 KB
testcase_20 AC 208 ms
25,344 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - m
Syntax OK

ソースコード

diff #

n, m, k = gets.chomp.split.map(&:to_i)

b = gets.chomp.split
op = b.shift
b.map!(&:to_i)
a = [] * n
h = Hash.new(0)
b.each do |bi|
  h[bi % k] += 1
end
n.times do
  a << gets.chomp.to_i % k
end

if op == '+'
  ans = 0
  a.each do |ai|
    ans += h[k - ai]
  end
  puts ans
  exit
end

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

ans = 0
ha.keys.each do |ka|
  hb.keys.each do |kb|
    if ka * kb % k == 0
      ans += ha[ka] * hb[kb]
    end
  end
end
puts ans
0