結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-14 23:06:15
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 422 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 34,848 KB
最終ジャッジ日時 2024-04-27 20:10:04
合計ジャッジ時間 5,160 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
19,100 KB
testcase_01 AC 83 ms
12,032 KB
testcase_02 AC 86 ms
12,416 KB
testcase_03 AC 85 ms
12,160 KB
testcase_04 AC 87 ms
12,032 KB
testcase_05 AC 85 ms
12,288 KB
testcase_06 AC 85 ms
12,160 KB
testcase_07 AC 86 ms
12,032 KB
testcase_08 AC 85 ms
12,032 KB
testcase_09 AC 85 ms
12,160 KB
testcase_10 AC 189 ms
20,736 KB
testcase_11 AC 221 ms
22,016 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
a = [] * n
h = Hash.new(0)
b.each do |bi|
  h[bi.to_i % k] += 1
end
b.sort!
n.times do
  a << gets.chomp.to_i % k
end

ans = 0
if op == '+'
  a.each do |ai|
    ans += h[k - ai]
  end
else
  ans += h[0] * n
  a.each do |ai|
    g = ai.gcd(k)
    if g > 1
      (k / g).step(k, k / g) do |j|
        ans += h[j]
      end
    end
  end
end

puts ans
0