結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-01 16:24:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 239 ms / 2,000 ms |
| コード長 | 846 bytes |
| コンパイル時間 | 210 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 113,660 KB |
| 最終ジャッジ日時 | 2024-06-28 05:18:31 |
| 合計ジャッジ時間 | 2,951 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 |
ソースコード
from collections import Counter,defaultdict
memo={}
def gcd(a,b):
if (a,b) in memo:return memo[(a,b)]
while b:a,b=b,a%b
memo[(a,b)]=a
return a
def main1(n,m,k,op,a,b):
if k==1:return m*n
if op=="+":
ca=dict(Counter([x%k for x in a]))
cb=dict(Counter([x%k for x in b]))
ans=0
for key,value in ca.items():
if (k-key)%k in cb:
ans+=cb[(k-key)%k]*value
return ans
else:
ca=dict(Counter([gcd(x,k) for x in a]))
cb=dict(Counter([gcd(x,k) for x in b]))
ans=0
for x in ca:
for y in cb:
if (x*y)%k==0:
ans+=ca[x]*cb[y]
return ans
import sys
input=sys.stdin.readline
if __name__=='__main__':
n,m,k=map(int,input().split())
b=list(input().split())
op=b[0]
b=list(map(int,b[1:]))
a=[int(input()) for _ in range(n)]
ret1=main1(n,m,k,op,a,b)
print(ret1)