結果
問題 | No.1929 Exponential Sequence |
ユーザー |
![]() |
提出日時 | 2022-04-04 23:47:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 318 ms / 2,000 ms |
コード長 | 736 bytes |
コンパイル時間 | 173 ms |
コンパイル使用メモリ | 81,908 KB |
実行使用メモリ | 150,664 KB |
最終ジャッジ日時 | 2024-09-14 03:50:07 |
合計ジャッジ時間 | 3,894 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 24 |
ソースコード
n,s=map(int,input().split()) a=list(map(int,input().split())) def calc(m,b): dp=[0] for i in b: dp_new=[] tmp=1 while i**tmp<=s: for j in dp: if j+i**tmp<=s: dp_new.append(j+i**tmp) tmp+=1 dp=dp_new dp.sort() dp2=[] for i in dp: if len(dp2)==0: dp2.append([i,1]) elif dp2[-1][0]==i: dp2[-1][1]+=1 else: dp2.append([i,1]) cum=[] tmp=0 for i,j in dp2: tmp+=j cum.append([i,tmp]) return dp2,cum n1=n//2 n2=n-n1 dp,_=calc(n1,a[:n1]) _,cum=calc(n2,a[n1:]) cum=cum[::-1] m1=len(dp) m2=len(cum) ans=0 now=0 for i in range(m1): while now<m2 and dp[i][0]+cum[now][0]>s: now+=1 if now!=m2: ans+=dp[i][1]*cum[now][1] print(ans)