結果
| 問題 | No.2709 1975 Powers |
| コンテスト | |
| ユーザー |
FromBooska
|
| 提出日時 | 2024-03-31 18:23:53 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 941 ms / 2,000 ms |
| コード長 | 1,043 bytes |
| 記録 | |
| コンパイル時間 | 384 ms |
| コンパイル使用メモリ | 85,048 KB |
| 実行使用メモリ | 206,592 KB |
| 最終ジャッジ日時 | 2026-04-16 22:53:48 |
| 合計ジャッジ時間 | 12,749 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
# 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)
FromBooska