結果

問題 No.974 最後の日までに
ユーザー ei1333333ei1333333
提出日時 2020-01-17 22:53:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 4,068 bytes
コンパイル時間 2,405 ms
コンパイル使用メモリ 206,704 KB
実行使用メモリ 22,324 KB
最終ジャッジ日時 2024-04-14 21:50:04
合計ジャッジ時間 8,050 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
20,032 KB
testcase_01 AC 107 ms
19,564 KB
testcase_02 AC 105 ms
19,516 KB
testcase_03 AC 104 ms
19,396 KB
testcase_04 AC 109 ms
19,776 KB
testcase_05 AC 105 ms
20,156 KB
testcase_06 AC 105 ms
19,520 KB
testcase_07 AC 110 ms
20,032 KB
testcase_08 AC 104 ms
19,892 KB
testcase_09 AC 129 ms
22,324 KB
testcase_10 AC 124 ms
20,396 KB
testcase_11 AC 120 ms
20,028 KB
testcase_12 AC 120 ms
19,900 KB
testcase_13 AC 128 ms
19,776 KB
testcase_14 AC 124 ms
19,904 KB
testcase_15 AC 118 ms
19,904 KB
testcase_16 AC 121 ms
20,840 KB
testcase_17 AC 103 ms
19,672 KB
testcase_18 AC 105 ms
20,288 KB
testcase_19 AC 105 ms
20,416 KB
testcase_20 AC 104 ms
19,644 KB
testcase_21 AC 104 ms
19,780 KB
testcase_22 AC 104 ms
20,164 KB
testcase_23 AC 103 ms
19,780 KB
testcase_24 AC 104 ms
19,520 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 115 ms
18,136 KB
testcase_28 AC 125 ms
19,416 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 129 ms
20,980 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 84 ms
12,424 KB
testcase_34 AC 147 ms
20,288 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 141 ms
20,160 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 80 ms
18,140 KB
testcase_41 AC 91 ms
21,072 KB
testcase_42 AC 143 ms
21,672 KB
testcase_43 AC 145 ms
20,996 KB
testcase_44 AC 125 ms
18,264 KB
testcase_45 AC 88 ms
12,424 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int W;
  cin >> W;
  // アルバイト
  // 学校->デート
  // ΣA[i]-ΣC[j]≧0
  // maximize ΣB[j]

  vector< int64 > A(W), B(W), C(W);
  for(int i = 0; i < W; i++) {
    cin >> A[i] >> B[i] >> C[i];
  }

  int M = W / 2; // [0,M) [M,W)

  if(W <= 1) {
    cout << 0 << endl;
    return 0;
  }

  // last = 0: アルバイト
  // last = 1: 学校
  // last = 2: デート

  vector< pair< int64, int64 > > prefix[3];

  MFP([&](auto gen, int l, int last, int64 aSum, int64 bSum) -> void {
    if(l == M) {
      prefix[last].emplace_back(aSum, bSum);
      return;
    }
    if(last == 0) {
      gen(l + 1, 2, aSum - C[l], bSum + B[l]);
    } else {
      gen(l + 1, 0, aSum, bSum);
      gen(l + 1, 1, aSum + A[l], bSum);
    }
  })(0, -1, 0, 0);


  vector< pair< int64, int64 > > suffix[3];

  auto gen = MFP([&](auto gen, int l, int first, int last, int64 aSum, int64 bSum) -> void {
    if(l == W) {
      suffix[first].emplace_back(aSum, bSum);
      return;
    }
    if(last == 0) {
      gen(l + 1, M == l ? 2 : first, 2, aSum - C[l], bSum + B[l]);
    } else {
      gen(l + 1, M == l ? 0 : first, 0, aSum, bSum);
      gen(l + 1, M == l ? 1 : first, 1, aSum + A[l], bSum);
    }
  });
  gen(M, -1, -1, 0, 0);
  gen(M, -1, 0, 0, 0);


  int64 ret = 0;

  auto solve = [&](vector< pair< int64, int64 > > &a, vector< pair< int64, int64 > > &b) {
    //a.first+b.first>=0のもの
    for(auto &p : a) {
      int pos = lower_bound(begin(b), end(b), make_pair(-p.first, -infll)) - begin(b);
      if(pos < b.size()) chmax(ret, p.second + b[pos].second);
    }
  };
  for(int i = 0; i < 3; i++) {
    sort(begin(suffix[i]), end(suffix[i]));
    int64 latte = -infll;
    for(int j = (int) suffix[i].size() - 1; j >= 0; j--) {
      chmax(latte, suffix[i][j].second);
      suffix[i][j].second = latte;
    }
  }


  solve(prefix[0], suffix[2]);
  solve(prefix[1], suffix[0]);
  solve(prefix[1], suffix[1]);
  solve(prefix[2], suffix[0]);
  solve(prefix[2], suffix[1]);
  cout << ret << endl;
}


0