結果

問題 No.2709 1975 Powers
ユーザー timi
提出日時 2024-03-31 14:09:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 82,292 KB
最終ジャッジ日時 2024-09-30 19:04:41
合計ジャッジ時間 3,467 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

N,P,Q=map(int, input().split())
A=list(map(int, input().split()))
A=sorted(A) 
ans=0
D,E={},{}
  
for i in range(N-1):
  for j in range(i+1,N):
    a=pow(10,A[i],P)
    b=pow(9,A[j],P)
    ab=(a+b)%P
    c=pow(7,A[i],P)
    d=pow(5,A[j],P)
    cd=(c+d)%P
    if ab not in D:
      D[ab]=[]
    D[ab].append(j)
    if cd not in E:
      E[cd]=[]
    E[cd].append(i)
    

for e in E:
  E[e]=sorted(E[e])
  
import bisect
for d in D:
  q=Q-d 
  if q in E:
    for now in D[d]:
      c=bisect.bisect_right(E[q],now)
      ans+=len(E[q])-c 
  q=P+Q-d 
  if q in E:
    for now in D[d]:
      c=bisect.bisect_right(E[q],now)
      ans+=len(E[q])-c 
print(ans)
0