結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
11,008 KB
testcase_01 AC 25 ms
10,880 KB
testcase_02 AC 25 ms
10,880 KB
testcase_03 AC 26 ms
10,880 KB
testcase_04 AC 28 ms
10,880 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 27 ms
10,880 KB
testcase_07 AC 26 ms
10,880 KB
testcase_08 AC 24 ms
11,008 KB
testcase_09 AC 25 ms
10,880 KB
testcase_10 AC 132 ms
21,860 KB
testcase_11 AC 181 ms
20,980 KB
testcase_12 AC 656 ms
33,164 KB
testcase_13 AC 94 ms
17,764 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 208 ms
22,004 KB
testcase_17 WA -
testcase_18 AC 679 ms
33,168 KB
testcase_19 AC 222 ms
18,408 KB
testcase_20 AC 326 ms
38,532 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]
        ans %= 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