結果

問題 No.2709 1975 Powers
ユーザー ThetaTheta
提出日時 2024-04-10 15:36:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,962 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 88,576 KB
最終ジャッジ日時 2024-04-10 15:36:36
合計ジャッジ時間 23,413 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,996 KB
testcase_01 AC 38 ms
54,272 KB
testcase_02 AC 89 ms
65,152 KB
testcase_03 AC 1,114 ms
76,800 KB
testcase_04 AC 1,693 ms
80,128 KB
testcase_05 AC 1,317 ms
78,720 KB
testcase_06 AC 536 ms
80,640 KB
testcase_07 AC 38 ms
54,784 KB
testcase_08 AC 523 ms
88,380 KB
testcase_09 AC 1,288 ms
81,408 KB
testcase_10 AC 39 ms
55,040 KB
testcase_11 AC 136 ms
67,968 KB
testcase_12 AC 261 ms
80,256 KB
testcase_13 AC 1,347 ms
88,344 KB
testcase_14 AC 309 ms
78,336 KB
testcase_15 AC 352 ms
78,336 KB
testcase_16 AC 1,086 ms
79,704 KB
testcase_17 AC 57 ms
64,000 KB
testcase_18 AC 259 ms
85,504 KB
testcase_19 AC 1,682 ms
87,276 KB
testcase_20 AC 73 ms
66,872 KB
testcase_21 AC 594 ms
88,576 KB
testcase_22 AC 1,867 ms
79,044 KB
testcase_23 AC 1,962 ms
87,180 KB
testcase_24 AC 1,955 ms
83,444 KB
testcase_25 AC 1,882 ms
78,464 KB
testcase_26 AC 1,848 ms
77,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right
from collections import defaultdict

from itertools import combinations
import sys


def printe(*args, end="\n", **kwargs):
    print(*args, end=end, file=sys.stderr, **kwargs)


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

    mod_P_pow_5 = defaultdict(list)
    for a_elm in A:
        mod_P_pow_5[pow(5, a_elm, P)].append(a_elm)

    ctr = 0
    for a, b, c in combinations(A, 3):
        c_mod = (pow(10, a, P) + pow(9, b, P) + pow(7, c, P)) % P
        rest_mod = (Q - c_mod) % P
        ctr += len(mod_P_pow_5[rest_mod]) - \
            bisect_right(mod_P_pow_5[rest_mod], c)
    print(ctr)


if __name__ == "__main__":
    main()
0