結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー NoneNone
提出日時 2021-02-27 17:50:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 117,076 KB
最終ジャッジ日時 2024-04-10 15:44:21
合計ジャッジ時間 3,103 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,264 KB
testcase_01 AC 40 ms
54,560 KB
testcase_02 AC 39 ms
54,704 KB
testcase_03 AC 38 ms
54,872 KB
testcase_04 AC 38 ms
55,052 KB
testcase_05 AC 39 ms
54,180 KB
testcase_06 AC 38 ms
53,912 KB
testcase_07 AC 42 ms
55,100 KB
testcase_08 AC 38 ms
54,672 KB
testcase_09 AC 39 ms
54,816 KB
testcase_10 AC 107 ms
91,000 KB
testcase_11 AC 122 ms
94,024 KB
testcase_12 AC 180 ms
96,116 KB
testcase_13 AC 97 ms
88,332 KB
testcase_14 AC 119 ms
89,856 KB
testcase_15 AC 100 ms
81,864 KB
testcase_16 AC 122 ms
93,416 KB
testcase_17 AC 89 ms
81,024 KB
testcase_18 AC 185 ms
95,824 KB
testcase_19 AC 130 ms
86,968 KB
testcase_20 AC 172 ms
117,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from math import gcd
N,M,K=map(int, input().split())
S=input().split()
op=S[0]
B=list(map(int,S[1:]))
A=list(int(input()) for _ in range(N))
res=0
if op=="+":
    C=defaultdict(int)
    for b in B:
        C[b%K]+=1
    for a in A:
        a%=K
        res+=C[(K-a)%K]
    print(res)
else:
    C=defaultdict(int)
    D=defaultdict(int)
    for a in A:
        C[gcd(a,K)]+=1
    for b in B:
        D[gcd(b,K)]+=1
    for key,val in C.items():
        for key2, val2 in D.items():
            if key*key2%K==0:
                res+=val*val2
    print(res)
0