結果

問題 No.974 最後の日までに
ユーザー risujirohrisujiroh
提出日時 2020-01-17 22:56:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,878 ms / 2,000 ms
コード長 1,679 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 176,896 KB
実行使用メモリ 31,112 KB
最終ジャッジ日時 2023-09-08 06:25:09
合計ジャッジ時間 56,366 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,401 ms
30,880 KB
testcase_01 AC 1,828 ms
30,836 KB
testcase_02 AC 1,815 ms
30,828 KB
testcase_03 AC 1,717 ms
30,836 KB
testcase_04 AC 1,756 ms
30,876 KB
testcase_05 AC 1,768 ms
31,100 KB
testcase_06 AC 1,850 ms
30,780 KB
testcase_07 AC 1,707 ms
30,888 KB
testcase_08 AC 1,724 ms
30,780 KB
testcase_09 AC 1,709 ms
31,000 KB
testcase_10 AC 1,766 ms
30,816 KB
testcase_11 AC 1,785 ms
30,896 KB
testcase_12 AC 1,645 ms
30,884 KB
testcase_13 AC 1,689 ms
30,828 KB
testcase_14 AC 1,715 ms
31,004 KB
testcase_15 AC 1,685 ms
30,912 KB
testcase_16 AC 1,670 ms
30,780 KB
testcase_17 AC 1,076 ms
4,380 KB
testcase_18 AC 1,074 ms
4,380 KB
testcase_19 AC 1,079 ms
4,376 KB
testcase_20 AC 1,105 ms
4,376 KB
testcase_21 AC 1,102 ms
4,380 KB
testcase_22 AC 1,053 ms
4,376 KB
testcase_23 AC 1,073 ms
4,380 KB
testcase_24 AC 1,081 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1,218 ms
23,244 KB
testcase_28 AC 1,878 ms
31,112 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1,082 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 900 ms
20,292 KB
testcase_34 AC 1,790 ms
30,816 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1,102 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 739 ms
4,380 KB
testcase_41 AC 1,083 ms
4,376 KB
testcase_42 AC 1,142 ms
4,380 KB
testcase_43 AC 1,139 ms
4,380 KB
testcase_44 AC 775 ms
4,376 KB
testcase_45 AC 597 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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();
    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];
        }
      }
      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)});
      auto it = end(mp1);
      for (auto e : mp0) {
        while (it != begin(mp1) and e.first + prev(it)->first > s) {
          --it;
        }
        if (it != begin(mp1)) {
          chmax(res, e.second + prev(it)->second);
        }
      }
    }
  }
  cout << res << '\n';
}
0