結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ryo_n
提出日時 2020-02-15 00:47:54
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 799 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 38,484 KB
最終ジャッジ日時 2024-11-16 02:07:48
合計ジャッジ時間 5,246 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import math

N, M, K = [int(x) for x in input().split()]
C = [x for x in input().split()]
B = [int(x) for x in C[1:]]
A = [int(input()) for _ in range(N)]

B_K = []
A_K = []
c_B_K = None
c_A_K = None
if C[0] == '+':
    B_K = [x % K for x in B]
    c_B_K = collections.Counter(B_K)
else:
    B_K = [math.gcd(x, K) for x in B]
    A_K = [math.gcd(x, K) for x in A]
    c_B_K = collections.Counter(B_K)
    c_A_K = collections.Counter(A_K)

ans = 0

if C[0] == '+':
    for j in range(N):
        ans += c_B_K[(K - A[j] % K) % K]
else:
    for b in c_B_K.keys():
        for a in c_A_K.keys():
            if (a * b) % K == 0:
                ans += c_B_K[b] * c_A_K[a]
print(ans)
0