結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-11-10 07:59:41
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,095 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 98,864 KB
最終ジャッジ日時 2023-11-10 07:59:52
合計ジャッジ時間 10,586 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
55,736 KB
testcase_01 AC 46 ms
55,864 KB
testcase_02 AC 47 ms
55,864 KB
testcase_03 AC 48 ms
55,736 KB
testcase_04 AC 50 ms
61,568 KB
testcase_05 AC 47 ms
55,736 KB
testcase_06 AC 47 ms
55,864 KB
testcase_07 AC 47 ms
55,864 KB
testcase_08 AC 46 ms
55,736 KB
testcase_09 AC 47 ms
55,736 KB
testcase_10 AC 98 ms
86,472 KB
testcase_11 AC 101 ms
88,152 KB
testcase_12 TLE -
testcase_13 AC 93 ms
84,372 KB
testcase_14 AC 104 ms
85,064 KB
testcase_15 AC 87 ms
79,584 KB
testcase_16 AC 105 ms
85,940 KB
testcase_17 AC 81 ms
79,448 KB
testcase_18 TLE -
testcase_19 AC 1,492 ms
83,312 KB
testcase_20 AC 163 ms
98,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N,M,K = map(int,input().split())
op,*B = input().split()
A = [int(input()) for _ in range(N)]
B = [int(i) for i in B]
if op == '+':
    
    ans = 0
    
    A = [a%K for a in A]
    B = [b%K for b in B]
    
    C = Counter(B)
    
    for a in A:
        
        ans += C[(K-a)%K]
        
    print(ans)

else:
    
    ans = 0
    
    
    def md(n):
        lower_divisors , upper_divisors = [], []
        i = 1
        while i*i <= n:
            if n % i == 0:
                lower_divisors.append(i)
                if i != n // i:
                    upper_divisors.append(n//i)
            i += 1
        return lower_divisors + upper_divisors[::-1]    
        
    P = md(K)
    
    C = defaultdict(int)
    
    for b in B:
        
        for p in P:
            
            if b%p==0:
                
                C[p] += 1
    
    for a in A:
        
        d = math.gcd(a,K)
        
        ans += C[K//d]
    print(ans)
    
0