結果
問題 | No.974 最後の日までに |
ユーザー | shibh308 |
提出日時 | 2019-12-07 13:52:54 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,903 bytes |
コンパイル時間 | 470 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 132,260 KB |
最終ジャッジ日時 | 2024-06-25 16:07:17 |
合計ジャッジ時間 | 6,786 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | AC | 1,062 ms
114,336 KB |
testcase_18 | AC | 1,045 ms
114,308 KB |
testcase_19 | AC | 1,057 ms
114,184 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 1,055 ms
114,300 KB |
testcase_24 | AC | 1,050 ms
114,324 KB |
testcase_25 | AC | 34 ms
11,392 KB |
testcase_26 | AC | 35 ms
11,520 KB |
testcase_27 | AC | 1,877 ms
95,628 KB |
testcase_28 | TLE | - |
testcase_29 | AC | 31 ms
11,392 KB |
testcase_30 | WA | - |
testcase_31 | AC | 31 ms
11,392 KB |
testcase_32 | AC | 30 ms
11,392 KB |
testcase_33 | AC | 1,632 ms
86,596 KB |
testcase_34 | TLE | - |
testcase_35 | WA | - |
testcase_36 | AC | 29 ms
11,264 KB |
testcase_37 | WA | - |
testcase_38 | AC | 30 ms
11,392 KB |
testcase_39 | AC | 31 ms
11,264 KB |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | AC | 31 ms
11,392 KB |
testcase_48 | WA | - |
testcase_49 | AC | 30 ms
11,392 KB |
testcase_50 | AC | 31 ms
11,392 KB |
testcase_51 | WA | - |
ソースコード
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)) 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, last_flag, money, val): if i == n: if last_flag: s[1].append((money, val)) else: v[1].append((money, val)) return if not flag: dfs2(i + 1, True, last_flag, money, val) if i == m: dfs2(i + 1, False, True, money - c[i], val + b[i]) else: dfs2(i + 1, False, last_flag, money + a[i], val) else: dfs2(i + 1, False, last_flag, 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(m, False, 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) assert(v_keys[i][idx] == money) v_vals[i][idx] = val for money, val in s[i]: idx = bisect.bisect_left(s_keys[i], money) assert(s_keys[i][idx] == money) 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[i].append(int(1e18)) s_vals[i].append(int(-1e18)) v_keys[i].append(int(1e18)) v_vals[i].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()