結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
19,232 KB
testcase_01 AC 74 ms
12,416 KB
testcase_02 AC 77 ms
12,416 KB
testcase_03 AC 75 ms
12,416 KB
testcase_04 AC 71 ms
12,416 KB
testcase_05 AC 70 ms
12,288 KB
testcase_06 AC 74 ms
12,288 KB
testcase_07 AC 71 ms
12,160 KB
testcase_08 AC 72 ms
12,160 KB
testcase_09 AC 73 ms
12,160 KB
testcase_10 AC 159 ms
20,736 KB
testcase_11 AC 189 ms
22,400 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
hh = {}

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

    next if g == 1

    v = k / g
    if hh[v]
      ans += hh[v]
      next
    end

    sum = 0
    v.step(k, v) do |j|
      sum += h[j]
    end

    hh[v] = sum
    ans += hh[v]
  end
end

puts ans
0