結果

問題 No.1929 Exponential Sequence
ユーザー titiatitia
提出日時 2022-05-07 01:39:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 14,172 KB
最終ジャッジ日時 2023-10-12 04:23:49
合計ジャッジ時間 3,276 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,700 KB
testcase_01 AC 20 ms
8,724 KB
testcase_02 AC 19 ms
8,520 KB
testcase_03 AC 265 ms
14,172 KB
testcase_04 AC 20 ms
8,496 KB
testcase_05 AC 19 ms
8,588 KB
testcase_06 AC 19 ms
8,532 KB
testcase_07 AC 19 ms
8,652 KB
testcase_08 AC 18 ms
8,632 KB
testcase_09 AC 19 ms
8,648 KB
testcase_10 AC 18 ms
8,596 KB
testcase_11 AC 18 ms
8,668 KB
testcase_12 AC 18 ms
8,724 KB
testcase_13 AC 19 ms
8,744 KB
testcase_14 AC 19 ms
8,592 KB
testcase_15 AC 24 ms
8,984 KB
testcase_16 AC 19 ms
8,556 KB
testcase_17 AC 18 ms
8,724 KB
testcase_18 AC 19 ms
8,488 KB
testcase_19 AC 19 ms
8,556 KB
testcase_20 AC 19 ms
8,656 KB
testcase_21 AC 261 ms
14,092 KB
testcase_22 AC 175 ms
11,724 KB
testcase_23 AC 253 ms
14,148 KB
testcase_24 AC 123 ms
11,084 KB
testcase_25 AC 258 ms
14,088 KB
testcase_26 AC 271 ms
14,096 KB
testcase_27 AC 19 ms
8,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 半分全列挙を思いつかないのはまずい。

import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

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

B=A[:n//2]
C=A[n//2:]

DP=dict()
DP[0]=1

for a in B:
    NDP=defaultdict(int)
    for dp in DP:
        for i in range(1,100):
            if dp+a**i<=S:
                NDP[dp+a**i]+=DP[dp]
            else:
                break
    DP=NDP

DP2=dict()
DP2[0]=1

for a in C:
    NDP=defaultdict(int)
    for dp in DP2:
        for i in range(1,100):
            if dp+a**i<=S:
                NDP[dp+a**i]+=DP2[dp]
            else:
                break
    DP2=NDP
            
LIST=sorted(DP2)
X=[]

now=0
for i in range(len(LIST)):
    now+=DP2[LIST[i]]
    X.append(now)

X.append(0)
ANS=0
for dp in DP:
    k=S-dp

    xx=bisect.bisect(LIST,k)
    ANS+=DP[dp]*X[xx-1]

print(ANS)
0