結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー nehan_der_thal
提出日時 2020-02-28 04:17:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 311 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 102,784 KB
最終ジャッジ日時 2024-11-16 03:39:36
合計ジャッジ時間 3,343 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import defaultdict
from math import gcd
N, M, K = map(int, input().split())
R = 0

bs = []
fs = []
for i in range(N+1):
    if i == 0:
        X = input().split()
        e = X[0] == '+'
        if e:
            d = defaultdict(int)
            for x in X[1:]:
                d[-int(x)%K] += 1
        else:
            bs = list(map(int, X[1:]))
            d = defaultdict(int)
            for b in bs:
                b = gcd(b, K)
                d[b] += 1
        continue
    x = int(input())
    if e:
        R += d[x%K]
    else:
        fs.append(x)
if e:
    print(R)
else:
    d2 = defaultdict(int)
    for b in fs:
        b = gcd(b, K)
        d2[b] += 1
    for c in d:
        for e in d2:
#            print(c, e, d[c])
            if gcd(c*e, K) % K == 0:
                R += d[c]*d2[e]
    print(R)
0