QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#49705 | #4412. Boss Rush | lqhsmash | AC ✓ | 1789ms | 20948kb | C++20 | 1.6kb | 2022-09-22 15:58:59 | 2022-09-22 15:59:01 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 19;
const int MOD = 998244353;
ll H, dp[1 << N], sum[1 << N];
int T, n, t[N], len[N];
vector<ll> d[N];
bool check (int x) {
for (int i = 0; i < (1 << n); i ++) dp[i] = -1;
dp[0] = 0;
ll ans = 0;
for (int i = 0; i < (1 << n); i ++) {
ans = max (dp[i], ans);
if (sum[i] > x) continue;
if (dp[i] == -1) continue;
for (int j = 0; j < n; j ++) {
if ((i >> j & 1) == 0) {
if (sum[i] + len[j] - 1 <= x) dp[i | (1 << j)] = max (dp[i] + d[j][len[j]], dp[i | (1 << j)]);
else dp[i | (1 << j)] = max (dp[i] + d[j][x - sum[i] + 1], dp[i | (1 << j)]);
}
}
}
return ans >= H;
}
int main () {
scanf ("%d", &T);
while (T --) {
scanf ("%d%lld", &n, &H);
for (int i = 0; i < n; i ++) {
scanf ("%d%d", &t[i], &len[i]);
d[i] = vector<ll> (len[i] + 1, 0);
for (int j = 1; j <= len[i]; j ++) {
scanf ("%lld", &d[i][j]);
d[i][j] += d[i][j - 1];
}
}
for (int i = 0; i < (1 << n); i ++) {
sum[i] = 0;
for (int j = 0; j < n; j ++) {
if (i >> j & 1) {
sum[i] += t[j];
}
}
}
int l = 0, r = 3e6, ans = -1;
while (l <= r) {
int mid = (l + r) >> 1;
if (check (mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
printf("%d\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1789ms
memory: 20948kb
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