結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
12,416 KB
testcase_01 AC 84 ms
12,160 KB
testcase_02 AC 87 ms
12,288 KB
testcase_03 AC 88 ms
12,032 KB
testcase_04 AC 90 ms
12,288 KB
testcase_05 AC 86 ms
12,160 KB
testcase_06 AC 86 ms
12,032 KB
testcase_07 AC 86 ms
12,288 KB
testcase_08 AC 86 ms
12,288 KB
testcase_09 AC 86 ms
12,288 KB
testcase_10 AC 164 ms
20,864 KB
testcase_11 AC 198 ms
22,144 KB
testcase_12 AC 467 ms
23,936 KB
testcase_13 AC 157 ms
18,432 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 184 ms
20,992 KB
testcase_17 WA -
testcase_18 AC 465 ms
24,064 KB
testcase_19 AC 224 ms
18,304 KB
testcase_20 AC 249 ms
28,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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{ A << gets.chomp.to_i }

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 % K]
  end
else
  da = Hash.new(0)
  db = Hash.new(0)
  A.each do |ai|
    da[ai.gcd(K)] += 1
  end
  B.each do |bi|
    db[bi.gcd(K)] += 1
  end
  da.each do |ka, va|
    db.each do |kb, vb|
      if ka * kb % K == 0
        z += va * vb
      end
    end
  end
end
puts z
0