結果

問題 No.974 最後の日までに
ユーザー kyo1kyo1
提出日時 2020-06-16 15:28:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 208,032 KB
実行使用メモリ 15,496 KB
最終ジャッジ日時 2023-09-16 10:58:49
合計ジャッジ時間 6,922 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
13,648 KB
testcase_01 AC 77 ms
13,896 KB
testcase_02 AC 73 ms
13,628 KB
testcase_03 AC 76 ms
14,428 KB
testcase_04 AC 83 ms
13,772 KB
testcase_05 AC 76 ms
13,684 KB
testcase_06 AC 76 ms
13,628 KB
testcase_07 AC 83 ms
14,472 KB
testcase_08 AC 78 ms
15,496 KB
testcase_09 AC 86 ms
13,688 KB
testcase_10 AC 84 ms
14,208 KB
testcase_11 AC 91 ms
14,496 KB
testcase_12 AC 90 ms
13,824 KB
testcase_13 AC 86 ms
14,004 KB
testcase_14 AC 84 ms
13,676 KB
testcase_15 AC 88 ms
13,820 KB
testcase_16 AC 90 ms
13,600 KB
testcase_17 AC 71 ms
13,868 KB
testcase_18 AC 71 ms
13,884 KB
testcase_19 AC 71 ms
13,904 KB
testcase_20 AC 72 ms
13,864 KB
testcase_21 AC 73 ms
13,952 KB
testcase_22 AC 74 ms
15,264 KB
testcase_23 AC 72 ms
13,744 KB
testcase_24 AC 72 ms
13,648 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 86 ms
12,220 KB
testcase_28 AC 95 ms
13,732 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 91 ms
13,680 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 66 ms
9,252 KB
testcase_34 AC 114 ms
13,620 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 106 ms
13,892 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 58 ms
12,228 KB
testcase_41 AC 66 ms
13,620 KB
testcase_42 AC 105 ms
13,604 KB
testcase_43 AC 109 ms
14,796 KB
testcase_44 AC 88 ms
12,288 KB
testcase_45 AC 66 ms
9,368 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int64_t INF = INT64_C(1) << 60;

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int W;
  cin >> W;
  vector<int64_t> A(W), B(W), C(W);
  for (int i = 0; i < W; i++) {
    cin >> A[i] >> B[i] >> C[i];
  }
  function<void(int, int, int64_t, int64_t, vector<pair<int64_t, int64_t>> &)> dfs =
      [&](int now, int end, int64_t money, int64_t love, vector<pair<int64_t, int64_t>> &vec) {
        if (now == end) {
          vec.emplace_back(make_pair(money, love));
          return;
        }
        dfs(now + 1, end, money + A[now], love, vec);
        if (now + 1 < end) dfs(now + 2, end, money - C[now + 1], love + B[now + 1], vec);
      };
  auto solve = [&](int w) {
    vector<pair<int64_t, int64_t>> A, B;
    dfs(0, w, 0, 0, A);
    dfs(w, W, 0, 0, B);
    sort(B.begin(), B.end());
    for (int i = (int)B.size() - 2; i > -1; i--) {
      chmax(B[i].second, B[i + 1].second);
    }
    int64_t res = 0;
    for (int i = 0; i < (int)A.size(); i++) {
      auto itr = lower_bound(B.begin(), B.end(), make_pair(-A[i].first, -INF));
      if (itr != B.end()) res = max(res, itr->second + A[i].second);
    }
    return res;
  };
  cout << max(solve(W / 2), solve(W / 2 + 1)) << '\n';
  return 0;
}
0