結果
問題 | No.2686 商品券の使い道 |
ユーザー | 👑 rin204 |
提出日時 | 2024-02-29 22:51:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 584 ms / 3,000 ms |
コード長 | 1,544 bytes |
コンパイル時間 | 324 ms |
コンパイル使用メモリ | 82,520 KB |
実行使用メモリ | 184,064 KB |
最終ジャッジ日時 | 2024-09-30 05:05:58 |
合計ジャッジ時間 | 18,209 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,224 KB |
testcase_01 | AC | 38 ms
52,736 KB |
testcase_02 | AC | 176 ms
101,376 KB |
testcase_03 | AC | 182 ms
101,376 KB |
testcase_04 | AC | 173 ms
102,144 KB |
testcase_05 | AC | 175 ms
101,504 KB |
testcase_06 | AC | 176 ms
101,504 KB |
testcase_07 | AC | 178 ms
101,504 KB |
testcase_08 | AC | 177 ms
101,248 KB |
testcase_09 | AC | 179 ms
101,856 KB |
testcase_10 | AC | 178 ms
102,016 KB |
testcase_11 | AC | 174 ms
101,632 KB |
testcase_12 | AC | 175 ms
101,504 KB |
testcase_13 | AC | 176 ms
101,632 KB |
testcase_14 | AC | 175 ms
101,836 KB |
testcase_15 | AC | 177 ms
101,632 KB |
testcase_16 | AC | 175 ms
101,632 KB |
testcase_17 | AC | 182 ms
101,632 KB |
testcase_18 | AC | 179 ms
101,760 KB |
testcase_19 | AC | 178 ms
101,888 KB |
testcase_20 | AC | 177 ms
101,376 KB |
testcase_21 | AC | 178 ms
101,504 KB |
testcase_22 | AC | 182 ms
101,568 KB |
testcase_23 | AC | 172 ms
101,504 KB |
testcase_24 | AC | 180 ms
101,888 KB |
testcase_25 | AC | 177 ms
101,760 KB |
testcase_26 | AC | 177 ms
101,632 KB |
testcase_27 | AC | 176 ms
101,376 KB |
testcase_28 | AC | 176 ms
101,504 KB |
testcase_29 | AC | 539 ms
183,424 KB |
testcase_30 | AC | 527 ms
184,064 KB |
testcase_31 | AC | 576 ms
183,680 KB |
testcase_32 | AC | 584 ms
183,680 KB |
testcase_33 | AC | 524 ms
183,936 KB |
testcase_34 | AC | 527 ms
183,552 KB |
testcase_35 | AC | 545 ms
183,552 KB |
testcase_36 | AC | 520 ms
183,424 KB |
testcase_37 | AC | 531 ms
183,780 KB |
testcase_38 | AC | 530 ms
183,700 KB |
testcase_39 | AC | 530 ms
183,888 KB |
testcase_40 | AC | 548 ms
183,552 KB |
testcase_41 | AC | 513 ms
183,808 KB |
testcase_42 | AC | 537 ms
184,064 KB |
testcase_43 | AC | 533 ms
183,552 KB |
testcase_44 | AC | 531 ms
183,904 KB |
testcase_45 | AC | 553 ms
183,840 KB |
testcase_46 | AC | 515 ms
183,708 KB |
evil_random20_1.txt | AC | 516 ms
183,680 KB |
evil_random20_2.txt | AC | 545 ms
184,012 KB |
evil_random20_3.txt | AC | 546 ms
183,424 KB |
ソースコード
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)