結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ayaoni
提出日時 2020-11-24 18:10:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 957 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 215,936 KB
最終ジャッジ日時 2024-07-23 18:42:52
合計ジャッジ時間 5,323 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 TLE * 1 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import gcd
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())


N,M,K = MI()
X = LS()
op = X[0]
B = [int(X[i]) for i in range(1,M+1)]
A = [I() for _ in range(N)]

if op == '+':
    count_A = [0]*K
    count_B = [0]*K
    for i in range(N):
        a = A[i]
        count_A[a % K] += 1
    for i in range(M):
        b = B[i]
        count_B[b % K] += 1
    ans = 0
    for i in range(K):
        ans += count_A[i]*count_B[(K-i) % K]
    print(ans)
else:
    div = []
    for i in range(1,int(K**.5)+1):
        if K % i == 0:
            div.append(i)
            if i != K//i:
                div.append(K//i)
    count_A = {}
    for d in div:
        r = sum(A[i] % d == 0 for i in range(N))
        count_A[d] = r
    ans = 0
    for b in B:
        r = K//gcd(K,b)
        ans += count_A[r]
    print(ans)
0