結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ryo_nryo_n
提出日時 2020-02-15 00:46:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 692 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 38,540 KB
最終ジャッジ日時 2024-04-27 20:43:07
合計ジャッジ時間 4,276 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
10,880 KB
testcase_01 AC 24 ms
10,880 KB
testcase_02 AC 24 ms
10,880 KB
testcase_03 AC 24 ms
10,880 KB
testcase_04 AC 24 ms
10,880 KB
testcase_05 AC 25 ms
10,880 KB
testcase_06 AC 25 ms
10,880 KB
testcase_07 AC 25 ms
11,008 KB
testcase_08 AC 25 ms
10,880 KB
testcase_09 AC 25 ms
10,880 KB
testcase_10 AC 135 ms
21,988 KB
testcase_11 AC 184 ms
21,100 KB
testcase_12 AC 709 ms
33,160 KB
testcase_13 AC 100 ms
17,756 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 212 ms
22,004 KB
testcase_17 WA -
testcase_18 AC 678 ms
33,164 KB
testcase_19 AC 229 ms
18,412 KB
testcase_20 AC 340 ms
38,540 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]
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