結果

問題 No.1929 Exponential Sequence
ユーザー sotanishysotanishy
提出日時 2022-05-06 21:50:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 543 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 86,456 KB
実行使用メモリ 118,104 KB
最終ジャッジ日時 2023-10-12 04:20:20
合計ジャッジ時間 7,315 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
71,484 KB
testcase_01 AC 100 ms
71,528 KB
testcase_02 AC 102 ms
71,328 KB
testcase_03 AC 543 ms
118,044 KB
testcase_04 AC 99 ms
71,284 KB
testcase_05 AC 98 ms
71,196 KB
testcase_06 AC 98 ms
71,548 KB
testcase_07 AC 98 ms
71,552 KB
testcase_08 AC 98 ms
71,580 KB
testcase_09 AC 99 ms
71,196 KB
testcase_10 AC 98 ms
71,344 KB
testcase_11 AC 99 ms
71,568 KB
testcase_12 AC 100 ms
71,132 KB
testcase_13 AC 106 ms
71,652 KB
testcase_14 AC 105 ms
71,352 KB
testcase_15 AC 121 ms
77,028 KB
testcase_16 AC 109 ms
76,196 KB
testcase_17 AC 97 ms
71,148 KB
testcase_18 AC 104 ms
71,548 KB
testcase_19 AC 98 ms
71,496 KB
testcase_20 AC 99 ms
71,480 KB
testcase_21 AC 438 ms
118,100 KB
testcase_22 AC 322 ms
112,688 KB
testcase_23 AC 417 ms
118,104 KB
testcase_24 AC 267 ms
101,348 KB
testcase_25 AC 438 ms
117,980 KB
testcase_26 AC 448 ms
117,860 KB
testcase_27 AC 101 ms
71,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

n, S = map(int, input().split())
a = list(map(int, input().split()))
sums = []

def rec(i, s, m):
    if i == m:
        if s <= S:
            sums.append(s)
        return
    k = 1
    while s+a[i]**k <= S:
        rec(i+1, s+a[i]**k, m)
        k += 1

rec(0, 0, n//2)
sums.sort()
ans = 0

def rec2(i, s):
    global ans
    if i == n:
        if s <= S:
            ans += bisect_right(sums, S-s)
        return
    k = 1
    while s+a[i]**k <= S:
        rec2(i+1, s+a[i]**k)
        k += 1

rec2(n//2, 0)
print(ans)
0