結果

問題 No.974 最後の日までに
ユーザー utouto97utouto97
提出日時 2020-01-21 22:03:05
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,927 bytes
コンパイル時間 1,223 ms
コンパイル使用メモリ 153,552 KB
実行使用メモリ 31,852 KB
最終ジャッジ日時 2023-09-20 12:49:33
合計ジャッジ時間 8,832 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

signed main() {
  int w;
  cin >> w;
  
  vi a(w), b(w), c(w);
  rep(i, 0, w) cin >> a[i] >> b[i] >> c[i];

  auto solve = [&](int n1, int n2){
    map<int, int> first;
    rep(mask, 0, 1<<n1){
      int money = 0, like = 0;
      bool ok = true;
      rep(i, 0, n1) if(mask & 1<<i){
        if(i+1 < n1 and (mask & 1<<(i+1))){
          like += b[i+1];
          money -= c[i+1];
          i++;
        } else {
          ok = false;
          break;
        }
      } else {
        money += a[i];
      }

      if(ok) first[money] = like;
    }

    int ma = -1e15;
    for(auto i = first.rbegin(); i != first.rend(); i++){
      chmax(ma, i->second);
      chmax(i->second, ma);
//    cout << i->first << " " << i->second << endl;
    }

    int ans = 0;
    rep(mask, 0, 1<<n2){
      int money = 0, like = 0;
      bool ok = true;
      rep(i, 0, n2) if(mask & 1<<i){
        if(i+1 < n2 and (mask & 1<<(i+1))){
          like += b[n1+i+1];
          money -= c[n1+i+1];
          i++;
        } else {
          ok = false;
          break;
        }
      } else {
        money += a[n1+i];
      }


      if(ok){
//        cout << money << " " << like << endl;
        auto j = first.lower_bound(-money);
        if(j != first.end()){
          chmax(ans, like + j->second);
        }
      }
    }

    return ans;
  };

  int n1 = w/2;
  int n2 = w-n1;

  cout << max(solve(n1, n2), solve(n1+1, n2-1)) << endl;
//  cout << solve(n1, n2) << endl;
//  cout << solve(n1+1, n2-1) << endl;

  return 0;
}
0