結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tpynerivertpyneriver
提出日時 2020-02-14 21:55:37
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 303 ms / 2,000 ms
コード長 1,075 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 95,104 KB
最終ジャッジ日時 2023-08-10 01:52:52
合計ジャッジ時間 4,644 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,636 KB
testcase_01 AC 79 ms
72,000 KB
testcase_02 AC 80 ms
71,888 KB
testcase_03 AC 81 ms
71,352 KB
testcase_04 AC 85 ms
76,864 KB
testcase_05 AC 78 ms
71,616 KB
testcase_06 AC 79 ms
71,652 KB
testcase_07 AC 80 ms
72,104 KB
testcase_08 AC 79 ms
71,536 KB
testcase_09 AC 79 ms
71,640 KB
testcase_10 AC 167 ms
91,268 KB
testcase_11 AC 126 ms
87,984 KB
testcase_12 AC 303 ms
89,076 KB
testcase_13 AC 119 ms
85,492 KB
testcase_14 AC 119 ms
85,368 KB
testcase_15 AC 106 ms
81,300 KB
testcase_16 AC 119 ms
84,080 KB
testcase_17 AC 102 ms
80,224 KB
testcase_18 AC 289 ms
89,160 KB
testcase_19 AC 239 ms
83,384 KB
testcase_20 AC 144 ms
95,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import Counter
readline = sys.stdin.readline

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
#約数列挙
def divi(n):
    res = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n//i)
    return res

N, M, K = map(int, readline().split())
op, *A = readline().strip().split()
A = [int(a) for a in A]
B = [int(readline()) for _ in range(N)]

if op == '+':
    C = Counter()
    for a in A:
        C[a%K] += 1
    
    res = 0
    for b in B:
        res += C[(-b)%K]
    print(res)
else:
    R = divi(K)
    R.sort()
    lr = len(R)
    Dr = Counter()
    table1 = [0]*lr
    table2 = [0]*lr
    for i in range(lr):
        Dr[R[i]] = i
    
    for a in A:
        table1[Dr[gcd(a, K)]] += 1
    
    for i in range(lr):
        k = R[i]
        v = table1[i]
        for j in range(i+1):
            if not k%R[j]:
                table2[j] += v
    ans = 0
    for b in B:
        ans += table2[Dr[K//gcd(b, K)]]
    print(ans)
0