結果
| 問題 | No.2709 1975 Powers | 
| コンテスト | |
| ユーザー |  FromBooska | 
| 提出日時 | 2024-03-31 18:23:53 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,043 bytes | 
| コンパイル時間 | 330 ms | 
| コンパイル使用メモリ | 82,392 KB | 
| 実行使用メモリ | 206,708 KB | 
| 最終ジャッジ日時 | 2024-09-30 21:15:50 | 
| 合計ジャッジ時間 | 27,577 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 TLE * 5 | 
ソースコード
# 200の4乗は不可能だが、200の3乗ならできる、最後だけ事前カウントしておくのはどうだろう
# これでダメなら先頭2項のmod、後半2項のmodで可能かも
N, P, Q = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
#print(A)
last_count = [[0]*P for i in range(N)]
for i in range(N-1, -1, -1):
    if i == N-1:
        calc = pow(5, A[i], P)
        last_count[i][calc] += 1
    else:
        for j in range(P):
            last_count[i][j] = last_count[i+1][j]
        calc = pow(5, A[i], P)
        last_count[i][calc] += 1
    #print('i', i, 'calc', calc)
        
#for l in last_count:
#    print(l)
# Ai!=Ajなのでダブりは考えなくていい
ans = 0
for a in range(N-3):
    for b in range(a+1, N-2):
        for c in range(b+1, N-1):
            calc = pow(10, A[a], P)+pow(9, A[b], P)+pow(7, A[c], P)
            needed = (Q-calc)%P
            #print(a, b, c, 'needed', needed)
            count = last_count[c+1][needed]
            ans += count
print(ans)
            
            
            
        