結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-11-10 07:59:41 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,095 bytes |
| コンパイル時間 | 316 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 99,140 KB |
| 最終ジャッジ日時 | 2024-09-26 00:42:44 |
| 合計ジャッジ時間 | 9,318 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 TLE * 2 |
ソースコード
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)