結果

問題 No.2709 1975 Powers
ユーザー konchakoncha
提出日時 2024-03-31 14:34:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 81,948 KB
実行使用メモリ 147,308 KB
最終ジャッジ日時 2024-09-30 19:41:20
合計ジャッジ時間 4,038 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter

def maker(l, x):
    sets = set(l)
    while True:
        current = (l[-1]*x) % P
        if current in sets:
            for i, item in enumerate(l):
                if item == current:
                    return (l[:i], l[i:])
        sets.add(current)
        l.append(current)


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

A.sort()

lo = []
for x in [10, 9, 7, 5]:
    loops = maker([x%P], x)
    lo.append([])

    for a in A:
        a -= 1
        if len(loops[0]) > a:
            lo[-1].append(loops[0][a])
        a -= len(loops[0])
        lo[-1].append(loops[1][a%len(loops[1])])

clo = [Counter(l) for l in lo]
answer = 0

clo3 = clo[3]

for i in range(N):
    x = lo[0][i]
    clo3[lo[3][i]] -= 1

    for j in range(i+1, N):
        clo3[lo[3][j]] -= 1
        for k in range(j+1, N):
            clo3[lo[3][k]] -= 1
            answer += clo3.get((Q-(x+lo[1][j]+lo[2][k])) % P, 0)

        for k in range(j+1, N):
            clo3[lo[3][k]] += 1
    for j in range(i+1, N):
        clo3[lo[3][j]] += 1

print(answer)
0