結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー %20%20
提出日時 2020-02-07 00:21:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 506 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 96,388 KB
最終ジャッジ日時 2024-04-27 19:27:21
合計ジャッジ時間 2,404 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
52,680 KB
testcase_01 AC 30 ms
52,584 KB
testcase_02 AC 31 ms
53,140 KB
testcase_03 AC 32 ms
52,820 KB
testcase_04 AC 32 ms
52,792 KB
testcase_05 AC 32 ms
53,216 KB
testcase_06 AC 31 ms
53,848 KB
testcase_07 AC 31 ms
52,956 KB
testcase_08 AC 31 ms
52,996 KB
testcase_09 AC 31 ms
52,444 KB
testcase_10 AC 87 ms
85,244 KB
testcase_11 AC 107 ms
88,936 KB
testcase_12 AC 159 ms
90,656 KB
testcase_13 AC 81 ms
85,200 KB
testcase_14 AC 99 ms
85,520 KB
testcase_15 AC 82 ms
79,776 KB
testcase_16 AC 95 ms
84,072 KB
testcase_17 AC 76 ms
79,872 KB
testcase_18 AC 158 ms
90,236 KB
testcase_19 AC 105 ms
83,940 KB
testcase_20 AC 122 ms
96,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
N,M,K=map(int,input().split())
op,*B=input().split()
B=map(int,B)
A=[int(input())for _ in range(N)]
z=0
if op=='+':
	d={}
	for b in B:
		b%=K
		if b in d:
			d[b]+=1
		else:
			d[b]=1
	for a in A:
		a=-a%K
		if a in d:
			z+=d[a]
else:
	da={}
	db={}
	for b in B:
		g=gcd(b,K)
		if g in db:
			db[g]+=1
		else:
			db[g]=1
	for a in A:
		g=gcd(a,K)
		if g in da:
			da[g]+=1
		else:
			da[g]=1
	for ka,va in da.items():
		for kb,vb in db.items():
			if ka*kb%K==0:
				z+=va*vb
print(z)
0