結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
12,160 KB
testcase_01 AC 84 ms
12,032 KB
testcase_02 AC 86 ms
12,032 KB
testcase_03 AC 85 ms
12,288 KB
testcase_04 AC 85 ms
12,032 KB
testcase_05 AC 85 ms
12,160 KB
testcase_06 AC 83 ms
12,032 KB
testcase_07 AC 85 ms
12,160 KB
testcase_08 AC 87 ms
12,032 KB
testcase_09 AC 85 ms
12,032 KB
testcase_10 AC 164 ms
20,480 KB
testcase_11 AC 203 ms
21,248 KB
testcase_12 AC 475 ms
23,040 KB
testcase_13 AC 157 ms
18,304 KB
testcase_14 AC 208 ms
18,944 KB
testcase_15 AC 168 ms
15,616 KB
testcase_16 AC 189 ms
20,992 KB
testcase_17 AC 143 ms
15,232 KB
testcase_18 AC 472 ms
23,040 KB
testcase_19 AC 230 ms
17,920 KB
testcase_20 AC 260 ms
28,800 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M, K = gets.split.map(&:to_i)
op, *B = gets.split
B.map!(&:to_i)
A = [] * N
N.times do
  A << gets.chomp.to_i
end
z = 0

if op == '+'
	d = Hash.new(0)
	B.each do |b|
		d[b % K] += 1
  end
	A.each do |a|
		if d[a]
			z += d[-a % K]
		end
	end
else
	da = {}
	db = {}
	B.each do |b|
		g=b.gcd(K)
		if db[g]
			db[g] += 1
		else
			db[g] = 1
		end
	end
	A.each do |a|
		g = a.gcd(K)
		if da[g]
			da[g] += 1
		else
			da[g] = 1
		end
	end
	da.each do |ka,va|
		db.each do |kb,vb|
			if ka * kb % K == 0
				z += va * vb
			end
		end
	end
end
p z
0