結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ayaoniayaoni
提出日時 2020-11-24 18:10:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 957 bytes
コンパイル時間 1,159 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 215,800 KB
最終ジャッジ日時 2023-10-01 01:08:03
合計ジャッジ時間 8,339 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,380 KB
testcase_01 AC 152 ms
71,500 KB
testcase_02 AC 73 ms
71,596 KB
testcase_03 AC 77 ms
75,928 KB
testcase_04 AC 76 ms
76,532 KB
testcase_05 AC 82 ms
75,852 KB
testcase_06 AC 74 ms
71,400 KB
testcase_07 AC 74 ms
71,816 KB
testcase_08 AC 76 ms
76,264 KB
testcase_09 AC 80 ms
79,080 KB
testcase_10 AC 259 ms
215,800 KB
testcase_11 AC 229 ms
89,164 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = [0]*K
    count_B = [0]*K
    for i in range(N):
        a = A[i]
        count_A[a % K] += 1
    for i in range(M):
        b = B[i]
        count_B[b % K] += 1
    ans = 0
    for i in range(K):
        ans += count_A[i]*count_B[(K-i) % K]
    print(ans)
else:
    div = []
    for i in range(1,int(K**.5)+1):
        if K % i == 0:
            div.append(i)
            if i != K//i:
                div.append(K//i)
    count_A = {}
    for d in div:
        r = sum(A[i] % d == 0 for i in range(N))
        count_A[d] = r
    ans = 0
    for b in B:
        r = K//gcd(K,b)
        ans += count_A[r]
    print(ans)
0