結果

問題 No.2709 1975 Powers
ユーザー budoubudou
提出日時 2024-04-07 06:51:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 564 ms / 2,000 ms
コード長 1,014 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 212,976 KB
最終ジャッジ日時 2024-04-07 06:51:37
合計ジャッジ時間 9,753 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
68,232 KB
testcase_01 AC 59 ms
68,232 KB
testcase_02 AC 200 ms
112,504 KB
testcase_03 AC 332 ms
141,564 KB
testcase_04 AC 513 ms
190,592 KB
testcase_05 AC 408 ms
166,340 KB
testcase_06 AC 188 ms
101,824 KB
testcase_07 AC 97 ms
81,160 KB
testcase_08 AC 374 ms
159,836 KB
testcase_09 AC 441 ms
176,052 KB
testcase_10 AC 99 ms
81,964 KB
testcase_11 AC 136 ms
91,696 KB
testcase_12 AC 303 ms
141,868 KB
testcase_13 AC 511 ms
199,476 KB
testcase_14 AC 205 ms
110,352 KB
testcase_15 AC 352 ms
155,644 KB
testcase_16 AC 282 ms
125,644 KB
testcase_17 AC 109 ms
84,372 KB
testcase_18 AC 311 ms
144,996 KB
testcase_19 AC 452 ms
177,900 KB
testcase_20 AC 193 ms
109,356 KB
testcase_21 AC 360 ms
159,068 KB
testcase_22 AC 564 ms
212,976 KB
testcase_23 AC 485 ms
184,512 KB
testcase_24 AC 330 ms
137,080 KB
testcase_25 AC 464 ms
179,740 KB
testcase_26 AC 511 ms
193,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import typing
import sys
# sys.setrecursionlimit(100100)
# from collections import defaultdict
input = lambda: sys.stdin.readline().strip()
inf = 10**18
mod = 998244353
# import heapq

def solve():
  N, P, Q = map(int, input().split())
  A = list(map(int,input().split()))
  A.sort()
  # 
  lft = [0 for _ in range(P)]
  rht = [0 for _ in range(P)]
  # 最初 b = 2から
  lft[(pow(10, A[0], P)+pow(9, A[1], P))%P] = 1

  # このとき c=3以降
  for c in range(2, N):
    for d in range(c+1, N):
      rht[(pow(7, A[c], P)+pow(5, A[d], P))%P] += 1
  ans = 0
  for p in range(P):
    ans += lft[p]*rht[(Q-p)%P]

  for b in range(2, N-2):
    # b終わりを追加
    lft = [0 for _ in range(P)]
    for a in range(b):
      lft[(pow(10, A[a], P)+pow(9, A[b], P))%P] += 1
    # bはじまりを削除
    for d in range(b+1, N):
      rht[(pow(7, A[b], P)+pow(5, A[d], P))%P] -= 1
    for p in range(P):
      ans += lft[p]*rht[(Q-p)%P]

  print(ans)
def main():
  t = 1
  for _ in range(t):
    solve()
main()
0