結果

問題 No.2709 1975 Powers
ユーザー nikoro256
提出日時 2024-03-31 14:14:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 414 ms / 2,000 ms
コード長 653 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 82,180 KB
実行使用メモリ 251,388 KB
最終ジャッジ日時 2024-09-30 19:12:37
合計ジャッジ時間 10,328 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

def makeexp(n):
    re=[1]
    for i in range(ma+2):
        re.append(re[-1]*n%P)
    return re

from collections import defaultdict
N,P,Q=map(int,input().split())
A=list(map(int,input().split()))
A=list(set(A))
A=sorted(A)
rightdic=defaultdict(int)
ma=max(A)
exp10=makeexp(10)
exp9=makeexp(9)
exp7=makeexp(7)
exp5=makeexp(5)
N=len(A)
for i in range(N):
    rightdic[exp5[A[i]]]+=1
ans=0
for i in range(N):
    #iを3番目とする。
    rightdic[exp5[A[i]]]-=1
    if i<2:
        continue
    for j in range(i):
        for k in range(j+1,i):
            left=(exp10[A[j]]+exp9[A[k]]+exp7[A[i]])%P
            ans+=rightdic[(Q-left)%P]
print(ans)
0