結果
問題 | No.974 最後の日までに |
ユーザー | shibh308 |
提出日時 | 2019-12-07 15:30:06 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,715 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 13,312 KB |
実行使用メモリ | 122,796 KB |
最終ジャッジ日時 | 2024-06-25 16:09:24 |
合計ジャッジ時間 | 77,064 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | AC | 33 ms
11,264 KB |
testcase_30 | WA | - |
testcase_31 | AC | 33 ms
11,264 KB |
testcase_32 | AC | 33 ms
11,392 KB |
testcase_33 | WA | - |
testcase_34 | TLE | - |
testcase_35 | WA | - |
testcase_36 | AC | 34 ms
11,264 KB |
testcase_37 | WA | - |
testcase_38 | AC | 33 ms
11,520 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | AC | 33 ms
11,392 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 34 ms
11,520 KB |
ソースコード
import bisect n = 0 a = [] b = [] c = [] m = [] v = [[], []] s = [[], []] def dfs(i, flag, money, val): if i == m: if flag: s[0].append((money, val)) else: v[0].append((money, val)) return if not flag: dfs(i + 1, True, money, val) dfs(i + 1, False, money + a[i], val) else: dfs(i + 1, False, money - c[i], val + b[i]) def dfs2(i, flag, money, val): if i == m - 1: if flag: s[1].append((money, val)) else: v[1].append((money, val)) return if not flag: dfs2(i - 1, True, money, val) dfs2(i - 1, False, money + a[i], val) else: dfs2(i - 1, False, money - c[i], val + b[i]) def calc(key1, key2, val1, val2): ans = 0 for k, v in zip(key1, val1): idx = bisect.bisect_left(key2, -k) ans = max(ans, v + val2[idx]) return ans def main(): global n, m, a, b, c n = int(input()) for i in range(n): a_, b_, c_ = tuple(map(int, input().split())) a.append(a_) b.append(b_) c.append(c_) m = n // 2 dfs(0, False, 0, 0) dfs2(n - 1, False, 0, 0) v_keys = [[], []] v_vals = [[], []] s_keys = [[], []] s_vals = [[], []] for i in range(2): v_tmp = [] s_tmp = [] for money, _ in v[i]: v_tmp.append(money) for money, _ in s[i]: s_tmp.append(money) v_tmp = sorted(v_tmp) s_tmp = sorted(s_tmp) for elm in v_tmp: if not v_keys[i] or v_keys[i][-1] != elm: v_keys[i].append(elm) for elm in s_tmp: if not s_keys[i] or s_keys[i][-1] != elm: s_keys[i].append(elm) v_vals[i] = [-int(1e18) for _ in range(len(v_keys[i]))] s_vals[i] = [-int(1e18) for _ in range(len(s_keys[i]))] for money, val in v[i]: idx = bisect.bisect_left(v_keys[i], money) v_vals[i][idx] = max(v_vals[i][idx], val) for money, val in s[i]: idx = bisect.bisect_left(s_keys[i], money) s_vals[i][idx] = max(s_vals[i][idx], val) for j in range(len(v_vals[i]) - 1, 0, -1): v_vals[i][j - 1] = max(v_vals[i][j - 1], v_vals[i][j]); for j in range(len(s_vals[i]) - 1, 0, -1): s_vals[i][j - 1] = max(s_vals[i][j - 1], s_vals[i][j]); s_keys[1].append(int(1e18)) s_vals[1].append(int(-1e18)) v_keys[1].append(int(1e18)) v_vals[1].append(int(-1e18)) ans = max(calc(s_keys[0], s_keys[1], s_vals[0], s_vals[1]), calc(v_keys[0], v_keys[1], v_vals[0], v_vals[1])) print(ans) if __name__ == '__main__': main()