結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| ユーザー |
titia
|
| 提出日時 | 2020-02-14 23:44:19 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,217 bytes |
| コンパイル時間 | 345 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 37,524 KB |
| 最終ジャッジ日時 | 2024-11-16 01:49:40 |
| 合計ジャッジ時間 | 7,545 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 TLE * 1 |
ソースコード
import sys
from collections import Counter
from math import sqrt
from math import gcd
input = sys.stdin.readline
N,M,K=map(int,input().split())
B=list(input().split())
A=[int(input()) for i in range(N)]
ANS=0
if B[0]=="+":
B=list(map(int,B[1:]))
A=Counter([a%K for a in A])
B=Counter([b%K for b in B])
for c in A:
ANS+=A[c]*B[K-c]
ANS+=A[0]*B[0]
print(ANS)
sys.exit()
B=list(map(int,B[1:]))
A=[gcd(a,K) for a in A]
B=[gcd(b,K) for b in B]
x=K
L=int(sqrt(x))
FACT=Counter()
for i in range(2,L+2):
while x%i==0:
FACT[i]+=1
x=x//i
if x!=1:
FACT[x]=FACT.get(x,0)+1
fs=list(FACT.keys())
fv=list(FACT.values())
LEN=len(fs)
SCA=Counter()
SCB=Counter()
for b in B:
sc=[0]*LEN
for i in range(LEN):
f=fs[i]
while b%f==0:
sc[i]+=1
b//=f
SCB[tuple(sc)]+=1
for a in A:
sc=[0]*LEN
for i in range(LEN):
f=fs[i]
while a%f==0:
sc[i]+=1
a//=f
SCA[tuple(sc)]+=1
def geq(sa,sb):
for i in range(LEN):
if fv[i]-sa[i]>sb[i]:
return 0
return SCA[sa]*SCB[sb]
for sa in SCA:
for sb in SCB:
ANS+=geq(sa,sb)
print(ANS)
titia