結果

問題 No.1929 Exponential Sequence
ユーザー lilictakalilictaka
提出日時 2022-05-21 12:08:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,730 ms / 2,000 ms
コード長 1,827 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 81,400 KB
実行使用メモリ 135,160 KB
最終ジャッジ日時 2023-10-20 15:53:31
合計ジャッジ時間 11,733 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,420 KB
testcase_01 AC 40 ms
59,564 KB
testcase_02 AC 77 ms
75,744 KB
testcase_03 AC 538 ms
135,160 KB
testcase_04 AC 783 ms
75,780 KB
testcase_05 AC 37 ms
57,520 KB
testcase_06 AC 35 ms
53,424 KB
testcase_07 AC 108 ms
75,888 KB
testcase_08 AC 34 ms
53,360 KB
testcase_09 AC 75 ms
75,516 KB
testcase_10 AC 39 ms
57,520 KB
testcase_11 AC 113 ms
75,488 KB
testcase_12 AC 1,701 ms
75,828 KB
testcase_13 AC 884 ms
75,752 KB
testcase_14 AC 1,730 ms
75,856 KB
testcase_15 AC 823 ms
76,288 KB
testcase_16 AC 109 ms
75,948 KB
testcase_17 AC 36 ms
57,520 KB
testcase_18 AC 33 ms
53,424 KB
testcase_19 AC 33 ms
53,360 KB
testcase_20 AC 42 ms
59,568 KB
testcase_21 AC 515 ms
134,848 KB
testcase_22 AC 390 ms
108,256 KB
testcase_23 AC 509 ms
134,588 KB
testcase_24 AC 318 ms
95,604 KB
testcase_25 AC 499 ms
123,116 KB
testcase_26 AC 530 ms
135,148 KB
testcase_27 AC 111 ms
75,488 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 itertools import product 
n,S = map(int,input().split())
A = list(map(int,input().split()))
if n >= 2:
    front = []
    back = []
    for a in A[:n//2]:
        front .append(a)
    for a in A[n//2:]:
        back.append(a)
    Plist = []
    for Ks in product([i for i in range(1,31)],repeat = len(front)):
        P = 0
        for l in range(len(front)):
            P += pow(front[l],Ks[l])
            if P > S:
                break

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


    
0