結果

問題 No.2686 商品券の使い道
ユーザー 👑 rin204rin204
提出日時 2024-02-29 22:51:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 559 ms / 3,000 ms
コード長 1,544 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 183,364 KB
最終ジャッジ日時 2024-03-19 00:37:01
合計ジャッジ時間 17,593 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 184 ms
101,168 KB
testcase_03 AC 181 ms
101,296 KB
testcase_04 AC 172 ms
101,296 KB
testcase_05 AC 176 ms
101,168 KB
testcase_06 AC 177 ms
101,168 KB
testcase_07 AC 175 ms
101,168 KB
testcase_08 AC 176 ms
101,168 KB
testcase_09 AC 176 ms
101,168 KB
testcase_10 AC 177 ms
101,296 KB
testcase_11 AC 176 ms
101,424 KB
testcase_12 AC 175 ms
101,296 KB
testcase_13 AC 175 ms
101,296 KB
testcase_14 AC 173 ms
101,296 KB
testcase_15 AC 177 ms
101,424 KB
testcase_16 AC 175 ms
101,424 KB
testcase_17 AC 179 ms
101,424 KB
testcase_18 AC 176 ms
101,424 KB
testcase_19 AC 177 ms
101,424 KB
testcase_20 AC 175 ms
101,296 KB
testcase_21 AC 178 ms
101,296 KB
testcase_22 AC 179 ms
101,296 KB
testcase_23 AC 173 ms
101,296 KB
testcase_24 AC 179 ms
101,296 KB
testcase_25 AC 172 ms
101,296 KB
testcase_26 AC 174 ms
101,296 KB
testcase_27 AC 183 ms
101,296 KB
testcase_28 AC 171 ms
101,296 KB
testcase_29 AC 550 ms
183,352 KB
testcase_30 AC 541 ms
183,344 KB
testcase_31 AC 521 ms
183,352 KB
testcase_32 AC 529 ms
183,352 KB
testcase_33 AC 529 ms
183,340 KB
testcase_34 AC 523 ms
183,352 KB
testcase_35 AC 544 ms
183,344 KB
testcase_36 AC 531 ms
183,364 KB
testcase_37 AC 529 ms
183,352 KB
testcase_38 AC 542 ms
183,352 KB
testcase_39 AC 530 ms
183,352 KB
testcase_40 AC 547 ms
183,360 KB
testcase_41 AC 511 ms
183,328 KB
testcase_42 AC 532 ms
183,352 KB
testcase_43 AC 531 ms
183,352 KB
testcase_44 AC 559 ms
183,352 KB
testcase_45 AC 559 ms
183,356 KB
testcase_46 AC 525 ms
183,364 KB
evil_random20_1.txt AC 521 ms
183,344 KB
evil_random20_2.txt AC 546 ms
183,320 KB
evil_random20_3.txt AC 543 ms
183,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def or_convolution(A, B, MOD=-1):
    n = max(len(A), len(B))
    l = (n - 1).bit_length()
    n = 1 << l
    A += [0] * (n - len(A))
    B += [0] * (n - len(B))

    def f(A):
        for i in range(l):
            for bit in range(n):
                if bit >> i & 1:
                    A[bit] += A[bit ^ (1 << i)]
                    if MOD != -1:
                        A[bit] %= MOD

    def invf(A):
        for i in range(l):
            for bit in range(n):
                if bit >> i & 1:
                    A[bit] -= A[bit ^ (1 << i)]
                    if MOD != -1:
                        A[bit] %= MOD

    f(A)
    f(B)
    if MOD != -1:
        C = [a * b % MOD for a, b in zip(A, B)]
    else:
        C = [a * b for a, b in zip(A, B)]
    invf(C)
    return C


n, m, q = map(int, input().split())
assert 1 <= n <= 20
assert 1 <= m <= 10**9
assert 1 <= q <= 10**9

A = [0] * n
B = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    assert 1 <= a <= 10**9
    assert 1 <= b <= 10**9

    A[i] = a
    B[i] = b

C = [0] * (1 << n)
W = [0] * (1 << n)
for bit in range(1 << n):
    for i in range(n):
        if bit >> i & 1:
            C[bit] = C[bit - (1 << i)] + A[i]
            W[bit] = W[bit - (1 << i)] + B[i]
            break

X = [0] * (1 << n)
Y = [0] * (1 << n)
for bit in range(1 << n):
    if C[bit] <= m:
        X[bit] = 1
    if C[bit] <= q:
        Y[bit] = 1

Z = or_convolution(X, Y)
ans = 0
for bit in range(1 << n):
    if Z[bit] > 0 and W[bit] > ans:
        ans = W[bit]

print(ans)
0