結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-15 00:29:00
言語 Ruby
(3.3.0)
結果
AC  
実行時間 502 ms / 2,000 ms
コード長 460 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 46,896 KB
最終ジャッジ日時 2023-08-10 03:06:57
合計ジャッジ時間 4,717 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,284 KB
testcase_01 AC 81 ms
15,304 KB
testcase_02 AC 82 ms
15,040 KB
testcase_03 AC 81 ms
15,296 KB
testcase_04 AC 81 ms
15,160 KB
testcase_05 AC 81 ms
15,356 KB
testcase_06 AC 83 ms
15,336 KB
testcase_07 AC 82 ms
15,236 KB
testcase_08 AC 81 ms
15,160 KB
testcase_09 AC 80 ms
15,036 KB
testcase_10 AC 148 ms
23,364 KB
testcase_11 AC 185 ms
25,100 KB
testcase_12 AC 502 ms
46,728 KB
testcase_13 AC 141 ms
20,840 KB
testcase_14 AC 183 ms
23,796 KB
testcase_15 AC 143 ms
18,832 KB
testcase_16 AC 159 ms
23,132 KB
testcase_17 AC 126 ms
18,476 KB
testcase_18 AC 497 ms
46,896 KB
testcase_19 AC 221 ms
26,152 KB
testcase_20 AC 222 ms
30,512 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N,M,K=gets.split.map &:to_i
op,*B=gets.split
B.map! &:to_i
A=$<.map &:to_i
z=0
if op=='+'
	d={}
	B.map{|b|
		b%=K
		if d[b]
			d[b]+=1
		else
			d[b]=1
		end
	}
	A.map{|a|
		a=-a%K
		if d[a]
			z+=d[a]
		end
	}
else
	da={}
	db={}
	B.map{|b|
		g=b.gcd K
		if db[g]
			db[g]+=1
		else
			db[g]=1
		end
	}
	A.map{|a|
		g=a.gcd K
		if da[g]
			da[g]+=1
		else
			da[g]=1
		end
	}
	da.map{|ka,va|
		db.map{|kb,vb|
			if ka*kb%K==0
				z+=va*vb
			end
		}
	}
end
p z
0