結果

問題 No.2709 1975 Powers
ユーザー norioc
提出日時 2024-04-01 01:48:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 801 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 144,988 KB
最終ジャッジ日時 2024-09-30 21:36:05
合計ジャッジ時間 17,849 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations

N, P, Q = map(int, input().split())
A = list(map(int, input().split()))
A.sort()


m = max(A) + 10
memo10 = [-1] * m
memo9 = [-1] * m
memo7 = [-1] * m
memo5 = [-1] * m


def f10(x):
    if memo10[x] != -1: return memo10[x]
    res = pow(10, x, P)
    memo10[x] = res
    return res


def f9(x):
    if memo9[x] != -1: return memo9[x]
    res = pow(9, x, P)
    memo9[x] = res
    return res


def f7(x):
    if memo7[x] != -1: return memo7[x]
    res = pow(7, x, P)
    memo7[x] = res
    return res


def f5(x):
    if memo5[x] != -1: return memo5[x]
    res = pow(5, x, P)
    memo5[x] = res
    return res


ans = 0
for a, b, c, d in combinations(A, 4):
    x = f10(a)
    x += f9(b)
    x += f7(c)
    x += f5(d)
    if x % P == Q:
        ans += 1

print(ans)
0