結果

問題 No.15 カタログショッピング
ユーザー convexineqconvexineq
提出日時 2020-11-24 06:12:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 236 ms / 5,000 ms
コード長 964 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 82,436 KB
最終ジャッジ日時 2023-10-01 00:47:20
合計ジャッジ時間 2,616 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,492 KB
testcase_01 AC 74 ms
71,440 KB
testcase_02 AC 74 ms
71,640 KB
testcase_03 AC 80 ms
75,608 KB
testcase_04 AC 72 ms
71,648 KB
testcase_05 AC 220 ms
82,384 KB
testcase_06 AC 233 ms
82,000 KB
testcase_07 AC 236 ms
82,436 KB
testcase_08 AC 228 ms
81,828 KB
testcase_09 AC 225 ms
81,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#a,b,c = map(int,readline().split())

def f(r):
    n = len(r)
    v = [0]
    for i in r:
        v += [vi+i for vi in v]
    
    v = [(v[i],i) for i in range(1<<n)]
    return v

n,s,*p = map(int,open(0).read().split())

a = f(p[:n//2])
b = f(p[n//2:])
#print(b)
a.sort(key=lambda x:x[0])
b.sort(key=lambda x:x[0])

from bisect import bisect_left,bisect_right

la = n//2
lb = n-la
ans = []
for bi,i in b:
    if s < bi: break
    l = bisect_left(a,(s-bi,-1))    
    r = bisect_right(a,(s-bi,1<<31))    

    for aj,j in a[l:r]:
        res = []
        v = 0
        for k in range(la):
            v += 1
            if j>>k&1:
                res.append(v)
        for k in range(lb):
            v += 1
            if i>>k&1:
                res.append(v)

        ans.append(res)                
        #print(aj,j,bi,i)

ans.sort()
for i in ans: print(*i)
0