結果

問題 No.974 最後の日までに
ユーザー kyo1kyo1
提出日時 2020-06-16 15:55:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,203 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 206,080 KB
実行使用メモリ 31,100 KB
最終ジャッジ日時 2023-09-16 11:02:51
合計ジャッジ時間 17,132 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 536 ms
30,868 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 556 ms
30,888 KB
testcase_06 AC 552 ms
30,820 KB
testcase_07 AC 561 ms
30,828 KB
testcase_08 AC 552 ms
30,872 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 572 ms
30,840 KB
testcase_14 AC 549 ms
30,832 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 29 ms
4,376 KB
testcase_18 AC 28 ms
4,380 KB
testcase_19 AC 27 ms
4,380 KB
testcase_20 AC 31 ms
4,380 KB
testcase_21 AC 31 ms
4,380 KB
testcase_22 AC 30 ms
4,380 KB
testcase_23 AC 30 ms
4,380 KB
testcase_24 AC 29 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 52 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 23 ms
4,376 KB
testcase_41 AC 28 ms
4,380 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
4,376 KB
testcase_47 WA -
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 1 ms
4,388 KB
testcase_51 AC 1 ms
4,388 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, map<int64_t, int64_t> &)> dfs =
      [&](int now, int end, int64_t money, int64_t love, map<int64_t, int64_t> &mp) {
        if (now == end) {
          chmax(mp[money], love);
          return;
        }
        dfs(now + 1, end, money + A[now], love, mp);
        if (now + 1 < end) dfs(now + 2, end, money - C[now + 1], love + B[now + 1], mp);
      };
  auto solve = [&](int w) {
    map<int64_t, int64_t> A, B;
    // B[INF] = -INF;
    // B[-INF] = -INF;
    dfs(0, w, 0, 0, A);
    dfs(w, W, 0, 0, B);
    int64_t res = 0;
    for (const auto &[key, value] : A) {
      auto itr = B.lower_bound(-key);
      if (itr != B.end()) res = max(res, itr->second + value);
    }
    return res;
  };
  cout << max(solve(W / 2), solve(W / 2 + 1)) << '\n';
  return 0;
}
0