結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ryo_nryo_n
提出日時 2020-02-15 00:47:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 656 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 36,236 KB
最終ジャッジ日時 2023-08-10 03:07:52
合計ジャッジ時間 4,299 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,784 KB
testcase_01 AC 18 ms
8,616 KB
testcase_02 AC 18 ms
8,736 KB
testcase_03 AC 19 ms
8,792 KB
testcase_04 AC 18 ms
8,788 KB
testcase_05 AC 20 ms
8,656 KB
testcase_06 AC 19 ms
8,732 KB
testcase_07 AC 18 ms
8,692 KB
testcase_08 AC 19 ms
8,688 KB
testcase_09 AC 18 ms
8,632 KB
testcase_10 AC 124 ms
20,516 KB
testcase_11 AC 163 ms
19,628 KB
testcase_12 AC 638 ms
30,912 KB
testcase_13 AC 90 ms
16,260 KB
testcase_14 AC 246 ms
19,836 KB
testcase_15 AC 182 ms
13,736 KB
testcase_16 AC 199 ms
20,500 KB
testcase_17 AC 125 ms
13,328 KB
testcase_18 AC 656 ms
30,976 KB
testcase_19 AC 208 ms
16,780 KB
testcase_20 AC 316 ms
36,236 KB
権限があれば一括ダウンロードができます

ソースコード

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