QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#42776#4412. Boss Rush01shijian#AC ✓1387ms15420kbC++172.0kb2022-08-03 18:30:292022-08-03 18:30:31

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-03 18:30:31]
  • 评测
  • 测评结果:AC
  • 用时:1387ms
  • 内存:15420kb
  • [2022-08-03 18:30:29]
  • 提交

answer

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

#ifdef LOCAL
  #include <debugger>
  clock_t start = clock();
#else
  #define debug(...) 42
#endif

template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }

void solve() {
  int n; ll H; cin >> n >> H;
  vector<vector<ll> > a(n);
  vector<int> t(n);

  ll sum = 0;
  for(int i = 0; i < n; i ++ ) {
    cin >> t[i];
    int len; cin >> len;
    a[i].resize(len + 1);
    for(int j = 1; j <= len; j ++ ) {
      cin >> a[i][j];
      sum += a[i][j];
      a[i][j] += a[i][j - 1];
    }
  }

  if(sum < H) {
    cout << "-1\n";
    return;
  }

  auto check = [&] (int x) -> bool {
    // vector<vector<int> > f(1 << n, vector<int>(n));
    vector<ll> f(1 << n);
    for(int i = 0; i < 1 << n; i ++ ) {
      int cnt = 0; 
      for(int j = 0; j < n; j ++ ) if(i >> j & 1) {
        cnt += t[j];
      }
      if(cnt > x) continue;
      for(int j = 0; j < n; j ++ ) if(not(i >> j & 1)) {
        // chkmax(f[i ^ (1 << j)], f[i] + (x - cnt + 1 >= t[j] ? a[j].back() : a[j][x - cnt + 1]));
        ll ret = f[i];
        if(x - cnt + 1 >= (int)a[j].size() - 1) {
          ret += a[j].back();
        } else {
          ret += a[j][x - cnt + 1];
        } 
        // debug(i ^ (1 << j), ret);
        if(ret >= H) return true;
        chkmax(f[i ^ (1 << j)], ret);
      }
    }
    // debug(*max_element(f.begin(), f.end()));
    return *max_element(f.begin(), f.end()) >= H;
  };

  int l = 0, r = 1800001;

  while(l < r) {
    int mid = (l + r) / 2;
    if(check(mid)) r = mid;
    else l = mid + 1;
  }
  cout << l << "\n";
}
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int T; cin >> T;
  while(T -- )
  solve();
#ifdef LOCAL
  clock_t ends = clock();
  // cout << "\n\nRunning Time : " << (double) (ends - start) / CLOCKS_PER_SEC * 1000 << "ms" << endl;
#endif
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1387ms
memory: 15420kb

input:

100
10 293367178351
89 52
117480172 951737726 356435682 180765874 775623083 281703307 290364363 366421773 989361116 796791408 389709469 534380525 412173405 463001602 578985383 272777986 833157533 444367936 841474617 472532665 952319800 583679381 924952511 892974994 105808118 171375863 320943603 4870...

output:

368
579
628
249
425
400
296
687
321
579
509
594
475
538
366
694
390
471
524
138
194
292
362
181
357
210
74
190
433
288
241
245
378
426
326
255
134
171
288
138
383
293
135
195
356
129
279
211
168
286
438
152
574
335
421
457
213
315
278
421
285
496
336
385
500
451
300
442
333
433
130
289
329
412
200
1...

result:

ok 100 lines