結果

問題 No.974 最後の日までに
ユーザー risujirohrisujiroh
提出日時 2020-01-17 22:47:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,690 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 177,188 KB
実行使用メモリ 26,972 KB
最終ジャッジ日時 2023-09-08 05:49:32
合計ジャッジ時間 63,357 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 TLE -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1,386 ms
4,380 KB
testcase_18 AC 1,387 ms
4,380 KB
testcase_19 AC 1,366 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,380 KB
testcase_27 WA -
testcase_28 TLE -
testcase_29 AC 1 ms
4,380 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 1 ms
4,380 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 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 1 ms
4,376 KB
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

auto chmax = [](auto&& l, auto r) { return exchange(l, l < r ? r : l) < r; };

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  auto fn = [](vector<long long> a, vector<long long> b, vector<long long> c) {
    int n = a.size();
    long long s = accumulate(begin(a), end(a), 0LL);
    map<long long, long long> mp;
    for (int bt = 0; bt < 1 << n; bt += 2) {
      bool ok = true;
      for (int i = 1; i < n; ++i) {
        if (bt >> i & 1 and bt >> (i - 1) & 1) {
          ok = false;
          break;
        }
      }
      if (not ok) {
        continue;
      }
      long long sw = 0, sv = 0;
      for (int i = 0; i < n; ++i) {
        if (bt >> i & 1) {
          sw += a[i - 1] + a[i] + c[i];
          sv += b[i];
        }
      }
      if (sw <= s) {
        chmax(mp[sw], sv);
      }
    }
    for (auto it = begin(mp); it != end(mp); ++it) {
      if (it != begin(mp)) {
        chmax(it->second, prev(it)->second);
      }
    }
    return mp;
  };
  int n;
  cin >> n;
  vector<long long> a(n), b(n), c(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
  }
  long long s = accumulate(begin(a), end(a), 0LL);
  long long res = 0;
  if (n >= 2) {
    for (int m : {n / 2, n / 2 + 1}) {
      auto mp0 = fn({begin(a), begin(a) + m}, {begin(b), begin(b) + m}, {begin(c), begin(c) + m});
      auto mp1 = fn({begin(a) + m, end(a)}, {begin(b) + m, end(b)}, {begin(c) + m, end(c)});
      for (auto e : mp0) {
        auto it = mp1.upper_bound(s - e.first);
        if (it != begin(mp1)) {
          chmax(res, e.second + prev(it)->second);
        }
      }
    }
  }
  cout << res << '\n';
}
0