結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 SPD_9X2
提出日時 2025-07-27 17:04:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 900 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 115,084 KB
最終ジャッジ日時 2025-07-27 17:04:40
合計ジャッジ時間 3,302 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/990

+の場合自明
*の場合、Kの約数について、?の倍数はいくつあるか記録

"""

import sys
from sys import stdin
from collections import deque
from collections import defaultdict
import math

N,M,K = map(int,stdin.readline().split())

opB = list(input().split())
op = opB[0]
B = list(map(int,opB[1:]))

A = [ int(stdin.readline()) for i in range(N) ]

if op == "+":

    dic = defaultdict(int)

    for a in A:
        dic[a%K] += 1

    ans = 0
    for b in B:
        ans += dic[(-b)%K]
    print (ans)

else:

    adic = defaultdict(int)
    bdic = defaultdict(int)

    for a in A:
        g = math.gcd(a,K)
        adic[g] += 1
    for b in B:
        g = math.gcd(b,K)
        bdic[g] += 1

    ans = 0
    for a in adic:
        for b in bdic:
            if a*b %K == 0:
                ans += adic[a] * bdic[b]

    print (ans)
0