結果

問題 No.2686 商品券の使い道
ユーザー hato336hato336
提出日時 2024-03-20 22:11:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,121 ms / 3,000 ms
コード長 1,097 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 97,680 KB
最終ジャッジ日時 2024-03-20 22:12:00
合計ジャッジ時間 32,640 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
85,048 KB
testcase_01 AC 134 ms
85,048 KB
testcase_02 AC 303 ms
91,448 KB
testcase_03 AC 300 ms
91,448 KB
testcase_04 AC 304 ms
91,448 KB
testcase_05 AC 304 ms
91,448 KB
testcase_06 AC 300 ms
91,448 KB
testcase_07 AC 297 ms
91,448 KB
testcase_08 AC 299 ms
91,448 KB
testcase_09 AC 301 ms
91,448 KB
testcase_10 AC 304 ms
91,448 KB
testcase_11 AC 302 ms
91,448 KB
testcase_12 AC 303 ms
91,448 KB
testcase_13 AC 300 ms
91,448 KB
testcase_14 AC 310 ms
91,448 KB
testcase_15 AC 311 ms
91,448 KB
testcase_16 AC 302 ms
91,448 KB
testcase_17 AC 301 ms
91,448 KB
testcase_18 AC 300 ms
91,448 KB
testcase_19 AC 300 ms
91,448 KB
testcase_20 AC 299 ms
91,448 KB
testcase_21 AC 304 ms
91,448 KB
testcase_22 AC 312 ms
91,448 KB
testcase_23 AC 299 ms
91,448 KB
testcase_24 AC 304 ms
91,448 KB
testcase_25 AC 308 ms
91,448 KB
testcase_26 AC 299 ms
91,448 KB
testcase_27 AC 305 ms
91,448 KB
testcase_28 AC 300 ms
91,448 KB
testcase_29 AC 1,020 ms
97,676 KB
testcase_30 AC 1,050 ms
97,548 KB
testcase_31 AC 1,078 ms
97,672 KB
testcase_32 AC 1,058 ms
97,676 KB
testcase_33 AC 1,073 ms
97,552 KB
testcase_34 AC 1,032 ms
97,676 KB
testcase_35 AC 1,121 ms
97,676 KB
testcase_36 AC 1,030 ms
97,552 KB
testcase_37 AC 1,064 ms
97,672 KB
testcase_38 AC 1,021 ms
97,676 KB
testcase_39 AC 1,053 ms
97,676 KB
testcase_40 AC 1,107 ms
97,676 KB
testcase_41 AC 1,082 ms
97,548 KB
testcase_42 AC 1,089 ms
97,676 KB
testcase_43 AC 1,037 ms
97,680 KB
testcase_44 AC 1,066 ms
97,672 KB
testcase_45 AC 1,080 ms
97,676 KB
testcase_46 AC 1,060 ms
97,676 KB
evil_random20_1.txt AC 1,031 ms
97,548 KB
evil_random20_2.txt AC 1,038 ms
97,652 KB
evil_random20_3.txt AC 1,004 ms
97,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
n,m,q = map(int,input().split())
item = [list(map(int,input().split())) for i in range(n)]
ans = 0
asu = [0 for i in range(1<<n)]
for s in range(1<<n):
    a,b = 0,0
    for j in range(n):
        if (s >> j) & 1 == 1:
            a += item[j][0]
            b += item[j][1]
    if a <= q:
        asu[s] = b

#or convolution andにする場合は配列をreverseしてからゼータ変換して点積をとってメビウス変換してreverseする
def subset_zeta_transform(s):
    for i in range(n):
        for j in range(1<<n):
            if (j >> i) & 1 == 0:
                s[j | (1 << i)] = max(s[j],s[j | (1 << i)])
    return s
asu = subset_zeta_transform(asu)

for s in range(1<<n):
    a,b = 0,0
    r = 0
    for j in range(n):
        if (s >> j) & 1 == 1:
            a += item[j][0]
            b += item[j][1]
        else:
            r += (1 << j)
    if a <= m:
        ans = max(ans,b + asu[r])
print(ans)
        
0