結果

問題 No.2709 1975 Powers
ユーザー RYOH2718RYOH2718
提出日時 2024-03-31 15:01:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 1,322 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 127,316 KB
最終ジャッジ日時 2024-03-31 15:01:07
合計ジャッジ時間 4,363 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 82 ms
115,936 KB
testcase_03 AC 114 ms
117,704 KB
testcase_04 AC 151 ms
117,932 KB
testcase_05 AC 150 ms
126,024 KB
testcase_06 AC 108 ms
120,260 KB
testcase_07 AC 69 ms
111,456 KB
testcase_08 AC 117 ms
122,468 KB
testcase_09 AC 149 ms
120,368 KB
testcase_10 AC 70 ms
112,372 KB
testcase_11 AC 81 ms
113,936 KB
testcase_12 AC 97 ms
121,524 KB
testcase_13 AC 186 ms
127,316 KB
testcase_14 AC 95 ms
115,360 KB
testcase_15 AC 110 ms
120,196 KB
testcase_16 AC 142 ms
124,800 KB
testcase_17 AC 76 ms
113,812 KB
testcase_18 AC 110 ms
121,380 KB
testcase_19 AC 190 ms
122,140 KB
testcase_20 AC 85 ms
116,784 KB
testcase_21 AC 104 ms
117,808 KB
testcase_22 AC 192 ms
118,888 KB
testcase_23 AC 216 ms
126,344 KB
testcase_24 AC 196 ms
124,704 KB
testcase_25 AC 182 ms
118,540 KB
testcase_26 AC 141 ms
118,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 標準入力された値を整数に変換する
def INT():
    return int(input())


# 標準入力された複数の値を整数に変換する
def MI():
    return map(int, input().split())


# 標準入力された複数の値を整数のリストに変換する
def LI():
    return list(map(int, input().split()))


from bisect import bisect_right

N, P, Q = MI()
A = LI()

mod10s = [0] * (max(A) + 1)
mod9s = [0] * (max(A) + 1)
mod7s = [0] * (max(A) + 1)
mod5s = [0] * P

cnt5s = [[] for _ in range(P)]
for i in range(N):
    mod10s[A[i]] = pow(10, A[i], P)
    mod9s[A[i]] = pow(9, A[i], P)
    mod7s[A[i]] = pow(7, A[i], P)
    mod5s[pow(5, A[i], P)] += 1
    cnt5s[pow(5, A[i], P)].append(A[i])

for i in range(P):
    cnt5s[i].sort()

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] >= A[j]:
            continue
        for k in range(N):
            if A[j] >= A[k]:
                continue
            p10 = mod10s[A[i]]
            p9 = mod9s[A[j]]
            p7 = mod7s[A[k]]

            three_mod = (p10 + p9 + p7) % P
            res = (Q - three_mod + P) % P
            # if len(cnt5s[res]) - bisect_right(cnt5s[res], A[k]):
            #     print(A[k], cnt5s[res], bisect_right(cnt5s[res], A[k]))
            ans += len(cnt5s[res]) - bisect_right(cnt5s[res], A[k])

print(ans)
0