結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tpynerivertpyneriver
提出日時 2020-02-14 21:52:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,076 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 92,424 KB
最終ジャッジ日時 2024-04-27 19:34:29
合計ジャッジ時間 2,516 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
54,416 KB
testcase_01 AC 34 ms
56,156 KB
testcase_02 AC 35 ms
55,448 KB
testcase_03 AC 34 ms
54,988 KB
testcase_04 AC 37 ms
59,660 KB
testcase_05 AC 35 ms
54,152 KB
testcase_06 AC 34 ms
54,560 KB
testcase_07 AC 34 ms
55,304 KB
testcase_08 AC 33 ms
54,200 KB
testcase_09 AC 33 ms
54,716 KB
testcase_10 AC 75 ms
82,744 KB
testcase_11 AC 76 ms
85,884 KB
testcase_12 AC 229 ms
87,516 KB
testcase_13 AC 75 ms
83,484 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 82 ms
82,060 KB
testcase_17 WA -
testcase_18 AC 224 ms
87,176 KB
testcase_19 AC 179 ms
81,960 KB
testcase_20 AC 101 ms
92,424 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[(K-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