結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー %20%20
提出日時 2020-02-07 00:21:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 763 ms / 2,000 ms
コード長 506 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 33,616 KB
最終ジャッジ日時 2024-04-27 19:27:03
合計ジャッジ時間 4,508 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,880 KB
testcase_01 AC 24 ms
10,880 KB
testcase_02 AC 26 ms
10,880 KB
testcase_03 AC 25 ms
11,008 KB
testcase_04 AC 25 ms
10,880 KB
testcase_05 AC 26 ms
10,880 KB
testcase_06 AC 25 ms
10,752 KB
testcase_07 AC 26 ms
10,880 KB
testcase_08 AC 28 ms
10,880 KB
testcase_09 AC 28 ms
10,880 KB
testcase_10 AC 134 ms
18,384 KB
testcase_11 AC 190 ms
17,248 KB
testcase_12 AC 763 ms
22,020 KB
testcase_13 AC 109 ms
15,828 KB
testcase_14 AC 276 ms
17,272 KB
testcase_15 AC 201 ms
14,608 KB
testcase_16 AC 200 ms
19,028 KB
testcase_17 AC 143 ms
13,696 KB
testcase_18 AC 760 ms
21,888 KB
testcase_19 AC 259 ms
15,828 KB
testcase_20 AC 319 ms
33,616 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