結果

問題 No.1929 Exponential Sequence
ユーザー powellpowell
提出日時 2023-09-30 10:17:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 600 ms / 2,000 ms
コード長 804 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 86,588 KB
実行使用メモリ 124,868 KB
最終ジャッジ日時 2023-09-30 10:17:18
合計ジャッジ時間 7,287 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,968 KB
testcase_01 AC 75 ms
70,980 KB
testcase_02 AC 77 ms
70,976 KB
testcase_03 AC 579 ms
124,756 KB
testcase_04 AC 73 ms
70,896 KB
testcase_05 AC 75 ms
70,636 KB
testcase_06 AC 74 ms
71,052 KB
testcase_07 AC 76 ms
71,052 KB
testcase_08 AC 75 ms
70,916 KB
testcase_09 AC 75 ms
70,496 KB
testcase_10 AC 75 ms
70,808 KB
testcase_11 AC 77 ms
70,892 KB
testcase_12 AC 74 ms
70,860 KB
testcase_13 AC 80 ms
70,892 KB
testcase_14 AC 73 ms
71,004 KB
testcase_15 AC 95 ms
76,300 KB
testcase_16 AC 83 ms
75,228 KB
testcase_17 AC 74 ms
70,992 KB
testcase_18 AC 75 ms
70,976 KB
testcase_19 AC 77 ms
70,920 KB
testcase_20 AC 77 ms
70,980 KB
testcase_21 AC 600 ms
124,300 KB
testcase_22 AC 420 ms
102,736 KB
testcase_23 AC 584 ms
124,428 KB
testcase_24 AC 329 ms
92,236 KB
testcase_25 AC 600 ms
124,868 KB
testcase_26 AC 588 ms
124,632 KB
testcase_27 AC 76 ms
70,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_right
from itertools import product

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

# 半分全列挙する
left, right = A[:N // 2], A[N // 2:]

# 左側を全列挙
left_all = []
for i, a in enumerate(left):
    tmp = []
    x = a
    while x < S:
        tmp.append(x)
        x *= a
    left_all.append(tmp)

# 左側の組合せをすべて作成
left_all_sorted = sorted(sum(comb) for comb in product(*left_all))

# 右側を全列挙
right_all = []
for i, a in enumerate(right):
    tmp = []
    x = a
    while x < S:
        tmp.append(x)
        x *= a
    right_all.append(tmp)

# 答えを得る
ans = 0
for comb in product(*right_all):
    sum_right = sum(comb)
    ok = bisect_right(left_all_sorted, S - sum_right)
    ans += ok

print(ans)
0