結果

問題 No.974 最後の日までに
ユーザー KeiKei
提出日時 2024-02-27 19:34:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 2,872 ms
コンパイル使用メモリ 112,356 KB
実行使用メモリ 14,696 KB
最終ジャッジ日時 2024-02-27 19:34:25
合計ジャッジ時間 6,851 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
14,696 KB
testcase_01 AC 100 ms
14,696 KB
testcase_02 AC 88 ms
14,696 KB
testcase_03 AC 89 ms
14,696 KB
testcase_04 AC 93 ms
14,696 KB
testcase_05 AC 97 ms
14,696 KB
testcase_06 AC 98 ms
14,696 KB
testcase_07 AC 92 ms
14,696 KB
testcase_08 AC 90 ms
14,696 KB
testcase_09 AC 91 ms
14,696 KB
testcase_10 AC 91 ms
14,696 KB
testcase_11 AC 89 ms
14,696 KB
testcase_12 AC 88 ms
14,696 KB
testcase_13 AC 92 ms
14,696 KB
testcase_14 AC 91 ms
14,696 KB
testcase_15 AC 88 ms
14,696 KB
testcase_16 AC 87 ms
14,696 KB
testcase_17 AC 80 ms
14,696 KB
testcase_18 AC 80 ms
14,696 KB
testcase_19 AC 80 ms
14,696 KB
testcase_20 AC 79 ms
14,696 KB
testcase_21 AC 80 ms
14,696 KB
testcase_22 AC 79 ms
14,696 KB
testcase_23 AC 79 ms
14,696 KB
testcase_24 AC 79 ms
14,696 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 95 ms
13,332 KB
testcase_28 AC 108 ms
14,696 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 94 ms
14,696 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 69 ms
9,508 KB
testcase_34 AC 124 ms
14,696 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 111 ms
14,696 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 54 ms
13,332 KB
testcase_41 AC 73 ms
14,696 KB
testcase_42 AC 112 ms
14,696 KB
testcase_43 AC 114 ms
14,696 KB
testcase_44 AC 93 ms
13,332 KB
testcase_45 AC 68 ms
9,508 KB
testcase_46 AC 2 ms
6,676 KB
testcase_47 AC 2 ms
6,676 KB
testcase_48 AC 2 ms
6,676 KB
testcase_49 AC 2 ms
6,676 KB
testcase_50 AC 2 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const long long INF = 1LL << 61;
int main() {
  int W;
  cin >> W;
  vector<long long> a(W), b(W), c(W);
  for (int i = 0; i < W; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  if (W == 1) {
    cout << 0 << endl;
  } else {
    vector<pair<long long, long long>> A;
    auto dfs = [&] (auto dfs, int l, int r, long long M, long long L) -> void {
      if (l == r) {
        A.push_back(make_pair(M, L));
        return;
      }
      dfs(dfs, l + 1, r, M + a[l], L);
      if (l + 2 <= r) {
        dfs(dfs, l + 2, r, M - c[l + 1], L + b[l + 1]);
      }
    };
    long long ans = 0;
    for (int mid : {W / 2, W / 2 - 1}) {
      dfs(dfs, 0, mid, 0LL, 0LL);
      vector<pair<long long, long long>> B = A;
      int N = B.size();
      sort(B.rbegin(), B.rend());
      long long MAXB = -INF;
      for (int i = 0; i < N; i++) {
        B[i].second = max(B[i].second, MAXB);
        MAXB = max(MAXB, B[i].second);
      }
      sort(B.begin(), B.end());
      A.clear();
      dfs(dfs, mid, W, 0LL, 0LL);
      B.push_back(make_pair(INF, -INF));
      N = A.size();
      for (int i = 0; i < N; i++) {
        auto itr = lower_bound(B.begin(), B.end(), make_pair(-A[i].first, 0LL));
        ans = max(ans, itr->second + A[i].second);
      }
      A.clear();
    }
    cout << ans << endl;
  }
}
0