結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ayaoniayaoni
提出日時 2020-11-24 18:30:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 111,276 KB
最終ジャッジ日時 2024-07-23 18:44:11
合計ジャッジ時間 2,776 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,280 KB
testcase_01 AC 38 ms
52,880 KB
testcase_02 AC 41 ms
52,516 KB
testcase_03 AC 39 ms
54,404 KB
testcase_04 AC 40 ms
52,864 KB
testcase_05 AC 38 ms
53,016 KB
testcase_06 AC 39 ms
54,196 KB
testcase_07 AC 39 ms
52,964 KB
testcase_08 AC 39 ms
53,044 KB
testcase_09 AC 39 ms
53,620 KB
testcase_10 AC 87 ms
86,908 KB
testcase_11 AC 97 ms
88,344 KB
testcase_12 AC 182 ms
89,864 KB
testcase_13 AC 76 ms
79,948 KB
testcase_14 AC 90 ms
85,004 KB
testcase_15 AC 77 ms
79,568 KB
testcase_16 AC 101 ms
89,204 KB
testcase_17 AC 73 ms
79,452 KB
testcase_18 AC 182 ms
89,844 KB
testcase_19 AC 108 ms
83,288 KB
testcase_20 AC 138 ms
111,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import gcd
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())


N,M,K = MI()
X = LS()
op = X[0]
B = [int(X[i]) for i in range(1,M+1)]
A = [I() for _ in range(N)]

if op == '+':
    count_A = {}
    count_B = {}
    for i in range(N):
        a = A[i] % K
        if a in count_A.keys():
            count_A[a] += 1
        else:
            count_A[a] = 1
    for i in range(M):
        b = B[i] % K
        if b in count_B.keys():
            count_B[b] += 1
        else:
            count_B[b] = 1
    ans = 0
    for i in count_A.keys():
        j = (K-i) % K
        if j in count_B.keys():
            ans += count_A[i]*count_B[j]
else:
    count_A = {}
    count_B = {}
    for a in A:
        g = gcd(a,K)
        if g in count_A.keys():
            count_A[g] += 1
        else:
            count_A[g] = 1
    for b in B:
        g = gcd(b,K)
        if g in count_B.keys():
            count_B[g] += 1
        else:
            count_B[g] = 1
    ans = 0
    for da in count_A.keys():
        e = K//da
        for db in count_B.keys():
            if db % e == 0:
                ans += count_A[da]*count_B[db]

print(ans)
0