結果
問題 |
No.1929 Exponential Sequence
|
ユーザー |
|
提出日時 | 2022-05-06 22:17:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 1,220 bytes |
コンパイル時間 | 160 ms |
コンパイル使用メモリ | 81,836 KB |
実行使用メモリ | 84,932 KB |
最終ジャッジ日時 | 2024-09-14 03:53:08 |
合計ジャッジ時間 | 3,006 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 24 |
ソースコード
#int(input()) #map(int, input().split()) #list(map(int, input().split())) n, S = map(int, input().split()) A = list(map(int, input().split())) B = A[n//2:] A = A[:n//2] d = dict() d[0] = 1 for i in range(len(A)): t = 1 a = A[i] nd = dict() while True: t *= a if t > S: break for x, v in d.items(): if x + t > S: continue elif x + t not in nd: nd[x+t] = v else: nd[x+t] += v d = dict(nd) da = dict(d) d = dict() d[0] = 1 for i in range(len(B)): t = 1 a = B[i] nd = dict() while True: t *= a if t > S: break for x, v in d.items(): if x + t > S: continue elif x + t not in nd: nd[x+t] = v else: nd[x+t] += v d = dict(nd) b = list(d.items()) b = sorted(b) s = [0] * (len(b) + 1) lb = [] for i in range(len(b)): s[i+1] = s[i] + b[i][1] lb.append(b[i][0]) # print(da) # print(d) import bisect ans = 0 # print(lb) for x, v in da.items(): t = bisect.bisect_right(lb, S-x) # print(t, S-x) ans += s[t] * v print(ans)