結果

問題 No.974 最後の日までに
ユーザー risujirohrisujiroh
提出日時 2020-01-17 23:02:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,714 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 179,980 KB
実行使用メモリ 30,084 KB
最終ジャッジ日時 2023-09-08 06:36:35
合計ジャッジ時間 36,699 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,688 ms
29,712 KB
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 AC 1,995 ms
29,908 KB
testcase_12 AC 1,995 ms
29,964 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 1,973 ms
29,900 KB
testcase_16 AC 1,979 ms
30,084 KB
testcase_17 AC 1,320 ms
4,380 KB
testcase_18 AC 1,259 ms
4,380 KB
testcase_19 AC 1,315 ms
4,376 KB
testcase_20 AC 1,248 ms
4,380 KB
testcase_21 AC 1,243 ms
4,380 KB
testcase_22 AC 1,239 ms
4,380 KB
testcase_23 AC 1,242 ms
4,376 KB
testcase_24 AC 1,238 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1,477 ms
20,728 KB
testcase_28 TLE -
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1,256 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1,113 ms
19,544 KB
testcase_34 TLE -
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1,274 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 838 ms
4,380 KB
testcase_41 AC 1,246 ms
4,380 KB
testcase_42 AC 1,282 ms
4,384 KB
testcase_43 AC 1,284 ms
4,376 KB
testcase_44 AC 865 ms
4,380 KB
testcase_45 AC 659 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 35 ms
4,380 KB
testcase_51 AC 1 ms
4,380 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);
    }
    vector<pair<long long, long long>> res(begin(mp), end(mp));
    for (int i = 1; i < (int)res.size(); ++i) {
      chmax(res[i].second, res[i - 1].second);
    }
    return res;
  };
  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 v0 = fn({begin(a), begin(a) + m}, {begin(b), begin(b) + m}, {begin(c), begin(c) + m});
      auto v1 = fn({begin(a) + m, end(a)}, {begin(b) + m, end(b)}, {begin(c) + m, end(c)});
      reverse(begin(v0), end(v0));
      int sz = v1.size(), i = 0;
      for (auto e : v0) {
        while (i < sz and e.first + v1[i].first <= s) {
          ++i;
        }
        if (i) {
          chmax(res, e.second + v1[i - 1].second);
        }
      }
    }
  }
  cout << res << '\n';
}
0