結果

問題 No.2709 1975 Powers
ユーザー KeeKee
提出日時 2024-03-31 23:03:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,390 ms / 2,000 ms
コード長 1,384 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,132 KB
最終ジャッジ日時 2024-03-31 23:03:18
合計ジャッジ時間 16,863 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,604 KB
testcase_01 AC 44 ms
55,604 KB
testcase_02 AC 77 ms
75,888 KB
testcase_03 AC 765 ms
75,992 KB
testcase_04 AC 1,180 ms
75,992 KB
testcase_05 AC 826 ms
75,992 KB
testcase_06 AC 325 ms
75,872 KB
testcase_07 AC 59 ms
68,520 KB
testcase_08 AC 295 ms
75,872 KB
testcase_09 AC 850 ms
75,992 KB
testcase_10 AC 55 ms
66,392 KB
testcase_11 AC 90 ms
75,876 KB
testcase_12 AC 131 ms
76,132 KB
testcase_13 AC 885 ms
75,992 KB
testcase_14 AC 184 ms
75,876 KB
testcase_15 AC 205 ms
75,876 KB
testcase_16 AC 678 ms
75,992 KB
testcase_17 AC 62 ms
72,708 KB
testcase_18 AC 149 ms
76,004 KB
testcase_19 AC 1,173 ms
75,992 KB
testcase_20 AC 71 ms
75,900 KB
testcase_21 AC 289 ms
75,872 KB
testcase_22 AC 1,381 ms
75,992 KB
testcase_23 AC 1,386 ms
75,992 KB
testcase_24 AC 1,390 ms
75,992 KB
testcase_25 AC 1,385 ms
75,992 KB
testcase_26 AC 1,385 ms
75,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python3

import bisect
import collections
import heapq
import itertools
import math
import os
import sys


B = (10, 9, 7, 5)


def main():
    n, p, q = read_ints()
    A = read_ints()
    A.sort()
    P = list2d(4, n)
    for c in range(4):
        for i in range(n):
            P[c][i] = pow(B[c], A[i], p)

    print(rec(n, p, q, P, 0, 0, 0))




def rec(n, p, q, P, i, c, s):
    if c == 4:
        if s == q:
            return 1
        return 0

    ans = 0
    for j in range(i, n - (3 - c)):
        ans += rec(n, p, q, P, j + 1, c + 1, (s + P[c][j]) % p)

    return ans


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def list2d(d1, d2, init=None):
    return [[init] * d2 for _ in range(d1)]


def list3d(d1, d2, d3, init=None):
    return [[[init] * d3 for _ in range(d2)] for _ in range(d1)]


def list4d(d1, d2, d3, d4, init=None):
    return [[[[init] * d4 for _ in range(d3)] for _ in range(d2)]
            for _ in range(d1)]


def debug(fmt, *args):
    if DEBUG:
        if args:
            print(fmt.format(*args), file=sys.stderr)
        else:
            print(fmt, file=sys.stderr)


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