結果

問題 No.974 最後の日までに
ユーザー risujirohrisujiroh
提出日時 2020-01-17 23:03:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,258 ms / 2,000 ms
コード長 1,699 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 174,788 KB
実行使用メモリ 17,256 KB
最終ジャッジ日時 2024-04-14 21:52:31
合計ジャッジ時間 48,141 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,220 ms
15,900 KB
testcase_01 AC 1,243 ms
15,580 KB
testcase_02 AC 1,237 ms
16,528 KB
testcase_03 AC 1,237 ms
15,916 KB
testcase_04 AC 1,236 ms
15,848 KB
testcase_05 AC 1,239 ms
15,572 KB
testcase_06 AC 1,237 ms
15,680 KB
testcase_07 AC 1,239 ms
16,368 KB
testcase_08 AC 1,238 ms
16,996 KB
testcase_09 AC 1,246 ms
15,700 KB
testcase_10 AC 1,237 ms
15,824 KB
testcase_11 AC 1,234 ms
15,772 KB
testcase_12 AC 1,236 ms
15,936 KB
testcase_13 AC 1,235 ms
16,972 KB
testcase_14 AC 1,236 ms
15,864 KB
testcase_15 AC 1,232 ms
16,160 KB
testcase_16 AC 1,231 ms
16,308 KB
testcase_17 AC 1,254 ms
16,108 KB
testcase_18 AC 1,255 ms
15,896 KB
testcase_19 AC 1,250 ms
17,256 KB
testcase_20 AC 1,254 ms
16,192 KB
testcase_21 AC 1,251 ms
16,264 KB
testcase_22 AC 1,257 ms
16,044 KB
testcase_23 AC 1,252 ms
16,028 KB
testcase_24 AC 1,251 ms
16,880 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 837 ms
10,336 KB
testcase_28 AC 1,240 ms
15,840 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 1,258 ms
16,008 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 637 ms
10,848 KB
testcase_34 AC 1,239 ms
16,292 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 1,257 ms
16,108 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 825 ms
10,592 KB
testcase_41 AC 1,227 ms
16,260 KB
testcase_42 AC 1,253 ms
15,652 KB
testcase_43 AC 1,254 ms
15,900 KB
testcase_44 AC 848 ms
10,592 KB
testcase_45 AC 647 ms
10,084 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 1 ms
6,940 KB
testcase_51 AC 2 ms
6,940 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();
    vector<pair<long long, long long>> res;
    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];
        }
      }
      res.emplace_back(sw, sv);
    }
    sort(begin(res), end(res));
    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