結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-07-01 16:24:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 116,112 KB
最終ジャッジ日時 2023-09-10 13:50:26
合計ジャッジ時間 4,263 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,512 KB
testcase_01 AC 96 ms
71,608 KB
testcase_02 AC 91 ms
71,384 KB
testcase_03 AC 90 ms
71,480 KB
testcase_04 AC 88 ms
71,524 KB
testcase_05 AC 90 ms
71,508 KB
testcase_06 AC 90 ms
71,600 KB
testcase_07 AC 89 ms
71,600 KB
testcase_08 AC 89 ms
71,480 KB
testcase_09 AC 90 ms
71,472 KB
testcase_10 AC 135 ms
93,068 KB
testcase_11 AC 123 ms
91,780 KB
testcase_12 AC 280 ms
92,368 KB
testcase_13 AC 144 ms
87,348 KB
testcase_14 AC 143 ms
88,076 KB
testcase_15 AC 124 ms
81,724 KB
testcase_16 AC 146 ms
90,624 KB
testcase_17 AC 120 ms
82,028 KB
testcase_18 AC 280 ms
92,560 KB
testcase_19 AC 179 ms
85,448 KB
testcase_20 AC 194 ms
116,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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