結果
問題 | No.2686 商品券の使い道 |
ユーザー | Yakumo221 |
提出日時 | 2024-03-20 23:34:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,571 ms / 3,000 ms |
コード長 | 1,988 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 82,316 KB |
実行使用メモリ | 188,340 KB |
最終ジャッジ日時 | 2024-09-30 09:37:14 |
合計ジャッジ時間 | 42,900 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,096 KB |
testcase_01 | AC | 34 ms
51,840 KB |
testcase_02 | AC | 406 ms
107,736 KB |
testcase_03 | AC | 408 ms
104,004 KB |
testcase_04 | AC | 417 ms
102,656 KB |
testcase_05 | AC | 397 ms
115,504 KB |
testcase_06 | AC | 435 ms
103,864 KB |
testcase_07 | AC | 373 ms
114,488 KB |
testcase_08 | AC | 383 ms
114,420 KB |
testcase_09 | AC | 423 ms
104,208 KB |
testcase_10 | AC | 408 ms
104,096 KB |
testcase_11 | AC | 434 ms
102,844 KB |
testcase_12 | AC | 446 ms
106,076 KB |
testcase_13 | AC | 358 ms
105,364 KB |
testcase_14 | AC | 462 ms
105,728 KB |
testcase_15 | AC | 436 ms
106,388 KB |
testcase_16 | AC | 421 ms
111,860 KB |
testcase_17 | AC | 452 ms
112,068 KB |
testcase_18 | AC | 420 ms
115,776 KB |
testcase_19 | AC | 431 ms
113,704 KB |
testcase_20 | AC | 346 ms
104,928 KB |
testcase_21 | AC | 409 ms
109,508 KB |
testcase_22 | AC | 438 ms
112,056 KB |
testcase_23 | AC | 439 ms
107,668 KB |
testcase_24 | AC | 446 ms
107,584 KB |
testcase_25 | AC | 462 ms
115,788 KB |
testcase_26 | AC | 449 ms
104,368 KB |
testcase_27 | AC | 422 ms
113,944 KB |
testcase_28 | AC | 360 ms
105,180 KB |
testcase_29 | AC | 1,434 ms
180,396 KB |
testcase_30 | AC | 1,362 ms
187,964 KB |
testcase_31 | AC | 1,571 ms
173,088 KB |
testcase_32 | AC | 1,383 ms
183,792 KB |
testcase_33 | AC | 1,454 ms
183,868 KB |
testcase_34 | AC | 1,392 ms
186,548 KB |
testcase_35 | AC | 1,503 ms
188,340 KB |
testcase_36 | AC | 1,362 ms
185,636 KB |
testcase_37 | AC | 1,415 ms
175,368 KB |
testcase_38 | AC | 1,328 ms
180,748 KB |
testcase_39 | AC | 1,442 ms
171,732 KB |
testcase_40 | AC | 1,508 ms
181,656 KB |
testcase_41 | AC | 1,321 ms
185,036 KB |
testcase_42 | AC | 1,487 ms
178,308 KB |
testcase_43 | AC | 1,475 ms
174,560 KB |
testcase_44 | AC | 1,429 ms
174,512 KB |
testcase_45 | AC | 1,515 ms
183,176 KB |
testcase_46 | AC | 1,467 ms
170,592 KB |
evil_random20_1.txt | AC | 1,416 ms
178,872 KB |
evil_random20_2.txt | AC | 1,468 ms
178,864 KB |
evil_random20_3.txt | AC | 1,504 ms
187,792 KB |
ソースコード
n, m, q = map(int, input().split()) # import sys # input = sys.stdin.readline # mp = map(int, sys.stdin.read().split()) # ab = list(zip(mp,mp)) ab = [] for i in range(n): a,b = map(int, input().split()) ab.append((a,b)) katidp = [[0 for i in range(1 << n)] for i in range(2)] resdp = [[0 for i in range(1 << n)] for i in range(2)] resdp[0][0] = m resdp[1][0] = q que = set([0]) for j in range(n): nq = set() while que: state = que.pop() mkati = katidp[0][state] qkati = katidp[1][state] mres = resdp[0][state] qres = resdp[1][state] for k in range(n): if state & (1 << k): continue else: nstate = state | (1 << k) nq.add(nstate) kati = ab[k][1] val = ab[k][0] if mres < val: nres = mres nkati = mkati else: nkati = mkati + kati nres = mres - val if katidp[0][nstate] < nkati: katidp[0][nstate] = nkati resdp[0][nstate] = nres elif katidp[0][nstate] == nkati: if resdp[0][nstate] < nres: resdp[0][nstate] = nres if qres < val: nres = qres nkati = qkati else: nkati = qkati + kati nres = qres - val if katidp[1][nstate] < nkati: katidp[1][nstate] = nkati resdp[1][nstate] = nres elif katidp[1][nstate] == nkati: if resdp[1][nstate] < nres: resdp[1][nstate] = nres que = nq # print(katidp) mask = (1 << n) - 1 ans = 0 for i in range(1 << n): j = mask ^ i ans = max(ans, katidp[0][i] + katidp[1][j]) print(ans)