結果

問題 No.1929 Exponential Sequence
ユーザー 👑 KazunKazun
提出日時 2022-05-06 23:39:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 615 ms / 2,000 ms
コード長 1,196 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 147,856 KB
最終ジャッジ日時 2023-10-12 04:23:36
合計ジャッジ時間 6,969 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,416 KB
testcase_01 AC 76 ms
71,368 KB
testcase_02 AC 75 ms
71,348 KB
testcase_03 AC 602 ms
134,484 KB
testcase_04 AC 77 ms
71,200 KB
testcase_05 AC 76 ms
71,308 KB
testcase_06 AC 77 ms
71,152 KB
testcase_07 AC 75 ms
71,160 KB
testcase_08 AC 77 ms
70,928 KB
testcase_09 AC 77 ms
71,200 KB
testcase_10 AC 80 ms
71,456 KB
testcase_11 AC 76 ms
71,052 KB
testcase_12 AC 76 ms
71,336 KB
testcase_13 AC 74 ms
70,940 KB
testcase_14 AC 75 ms
71,332 KB
testcase_15 AC 94 ms
76,720 KB
testcase_16 AC 88 ms
76,300 KB
testcase_17 AC 78 ms
71,308 KB
testcase_18 AC 76 ms
71,416 KB
testcase_19 AC 76 ms
71,296 KB
testcase_20 AC 77 ms
71,196 KB
testcase_21 AC 615 ms
145,192 KB
testcase_22 AC 430 ms
108,952 KB
testcase_23 AC 615 ms
147,856 KB
testcase_24 AC 338 ms
99,308 KB
testcase_25 AC 606 ms
133,640 KB
testcase_26 AC 608 ms
134,712 KB
testcase_27 AC 77 ms
71,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Binary_Search_Small_Count(A, x, equal=False, sort=False):
    """二分探索によって, x 未満の要素の個数を調べる.

    A: リスト
    x: 調べる要素
    sort: ソートをする必要があるかどうか (True で必要)
    equal: True のときは x "未満" が x "以下" になる
    """
    if sort:
        A.sort()

    if len(A)==0 or A[0]>x or ((not equal) and A[0]==x):
        return 0

    L,R=0,len(A)
    while R-L>1:
        C=L+(R-L)//2
        if A[C]<x or (equal and A[C]==x):
            L=C
        else:
            R=C

    return L+1
#==================================================
def f(B):
    X=[]
    I=[]
    for b in B:
        t=0
        while pow(b,t+1)<=S:
            t+=1
        I.append(range(1,t+1))

    for P in product(*I):
        s=0
        for b,p in zip(B,P):
            s+=pow(b,p)
        if s<=S:
            X.append(s)
    X.sort()
    return X

#==================================================
from itertools import product

N,S=map(int,input().split())
A=list(map(int,input().split()))

B=A[:N//2]; C=A[N//2:]

X=f(B)
Y=f(C)

ans=0
for x in X:
    ans+=Binary_Search_Small_Count(Y, S-x, True)

print(ans)
0