結果

問題 No.1929 Exponential Sequence
ユーザー lilictakalilictaka
提出日時 2022-05-21 11:52:58
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,510 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 84,708 KB
最終ジャッジ日時 2023-10-20 15:52:44
合計ジャッジ時間 13,184 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,376 KB
testcase_01 AC 43 ms
61,520 KB
testcase_02 AC 83 ms
75,852 KB
testcase_03 AC 523 ms
84,708 KB
testcase_04 AC 975 ms
76,064 KB
testcase_05 AC 42 ms
59,476 KB
testcase_06 AC 38 ms
55,380 KB
testcase_07 AC 125 ms
75,988 KB
testcase_08 AC 39 ms
55,316 KB
testcase_09 AC 91 ms
75,724 KB
testcase_10 AC 42 ms
59,476 KB
testcase_11 AC 129 ms
75,784 KB
testcase_12 TLE -
testcase_13 AC 1,133 ms
75,956 KB
testcase_14 TLE -
testcase_15 AC 1,057 ms
76,692 KB
testcase_16 AC 118 ms
76,384 KB
testcase_17 AC 42 ms
59,476 KB
testcase_18 AC 38 ms
55,380 KB
testcase_19 AC 38 ms
55,316 KB
testcase_20 AC 44 ms
61,524 KB
testcase_21 AC 528 ms
84,704 KB
testcase_22 AC 409 ms
82,280 KB
testcase_23 AC 518 ms
84,660 KB
testcase_24 AC 354 ms
79,252 KB
testcase_25 AC 524 ms
84,652 KB
testcase_26 AC 525 ms
84,704 KB
testcase_27 AC 147 ms
75,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
def acum(List):#累積和
    rev = [0 for _ in range(len(List))]
    for i in range(len(List)):
        if i == 0:
            rev[i] = List[i]
        else:
           rev[i] = rev[i-1] + List[i] 
    return rev
from collections import defaultdict
from itertools import product 
n,S = map(int,input().split())
A = list(map(int,input().split()))
cntP = defaultdict(int)
cntQ = defaultdict(int)
if n >= 2:
    front = []
    back = []
    for a in A[:n//2]:
        front .append(a)
    for a in A[n//2:]:
        back.append(a)
    for Ks in product([i for i in range(1,33)],repeat = len(front)):
        P = 0
        for l in range(len(front)):
            P += pow(front[l],Ks[l])
            if P > S:
                break

        if P <= S:
            cntP[P] += 1
    qlist = set()
    for Ks in product([i for i in range(1,33)],repeat=len(back)):
        Q = 0
        for l in range(len(back)):
            Q += pow(back[l],Ks[l])
            if Q > S:
                break
        if Q <= S:
            cntQ[Q] += 1
            qlist.add(Q)
    qlist = sorted(list(qlist))
    value = []
    for q in qlist:
        value.append(cntQ[q])
    cum = acum(value)
    ans = 0
    for p in cntP.keys():
        index = bisect_left(qlist,S-p+1) -1
        if index == -1:
            continue
        ans += cntP[p] * cum[index] 
    print(ans)
else:
    for k in range(1,33):
        if pow(A[0],k) <= S:
            pass
        else:
            break
    print(k-1)
0