結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー qqqqq
提出日時 2020-02-14 23:27:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,449 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 82,044 KB
実行使用メモリ 110,056 KB
最終ジャッジ日時 2024-11-16 01:41:14
合計ジャッジ時間 5,660 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__


n,m,k = map(int, input().split())
op, *B = input().split()
B = list(map(int, B))
A = [int(input()) for i in range(n)]

from collections import defaultdict
from math import gcd


if op == "+":
    d = defaultdict(int)
    for bi in B:
        d[bi%k] += 1

    ans = 0
    for ai in A:
        target = (-ai)%k
        ans += d[target]
else:
    d = defaultdict(int)
    for bi in B:
        d[gcd(bi, k)] += 1

    ans = 0
    for ai in A:
        c = gcd(ai, k)
        for key, value in d.items():
            if key*c%k == 0:
                ans += value

print(ans)
0