結果

問題 No.1929 Exponential Sequence
ユーザー 👑 KazunKazun
提出日時 2022-05-06 23:37:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,105 bytes
コンパイル時間 1,069 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 145,488 KB
最終ジャッジ日時 2023-09-20 06:58:24
合計ジャッジ時間 5,851 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
76,308 KB
testcase_01 AC 95 ms
77,064 KB
testcase_02 AC 170 ms
76,792 KB
testcase_03 AC 638 ms
145,488 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

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=[]
    for P in product(range(1,31), repeat=len(B)):
        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