結果
| 問題 | 
                            No.15 カタログショッピング
                             | 
                    
| コンテスト | |
| ユーザー | 
                             square1001
                         | 
                    
| 提出日時 | 2022-02-17 14:30:06 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 292 ms / 5,000 ms | 
| コード長 | 857 bytes | 
| コンパイル時間 | 81 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 18,432 KB | 
| 最終ジャッジ日時 | 2024-06-29 07:39:50 | 
| 合計ジャッジ時間 | 2,353 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
ソースコード
import bisect # Input N, S = map(int, input().split()) A = [ int(input()) for i in range(N) ] A.reverse() # Enumerate all sep = N // 2 cost1 = [ 0 ] * (1 << sep) for i in range(0, sep): for j in range(0, 1 << i): cost1[j | (1 << i)] = cost1[j] + A[i] cost2 = [ 0 ] * (1 << (N - sep)) for i in range(0, N - sep): for j in range(0, 1 << i): cost2[j | (1 << i)] = cost2[j] + A[i + sep] # Meet-in-the-middle scost1 = sorted([ (cost1[i], i) for i in range(0, 1 << sep) ]) for i in range((1 << (N - sep)) - 1, -1, -1): l = bisect.bisect_left(scost1, (S - cost2[i], -1)) r = bisect.bisect_left(scost1, (S - cost2[i] + 1, -1)) for j in range(r - 1, l - 1, -1): vals = list(filter(lambda x: ((i >> (N - sep - x)) & 1) == 1, range(1, N - sep + 1))) + list(filter(lambda x: ((scost1[j][1] >> (N - x)) & 1) == 1, range(N - sep + 1, N + 1))) print(*vals)
            
square1001