結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-07-01 16:23:34
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 804 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 92,052 KB
最終ジャッジ日時 2023-09-10 13:48:55
合計ジャッジ時間 5,201 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 72 ms
71,004 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 106 ms
91,028 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0