結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ayaoniayaoni
提出日時 2020-11-24 18:26:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,242 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 112,344 KB
最終ジャッジ日時 2023-10-01 01:09:20
合計ジャッジ時間 3,694 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,028 KB
testcase_01 WA -
testcase_02 AC 75 ms
71,076 KB
testcase_03 AC 75 ms
70,828 KB
testcase_04 AC 75 ms
71,072 KB
testcase_05 AC 76 ms
70,904 KB
testcase_06 AC 74 ms
71,180 KB
testcase_07 WA -
testcase_08 AC 74 ms
70,964 KB
testcase_09 AC 74 ms
70,944 KB
testcase_10 AC 123 ms
87,516 KB
testcase_11 AC 127 ms
88,756 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 120 ms
85,380 KB
testcase_15 AC 104 ms
80,140 KB
testcase_16 AC 131 ms
89,984 KB
testcase_17 AC 103 ms
79,988 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 161 ms
112,344 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 d in count_A.keys():
        e = K//d
        if e in count_B.keys():
            ans += count_A[d]*count_B[e]

print(ans)
0