QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#49703 | #4412. Boss Rush | lqhsmash | RE | 0ms | 0kb | C++20 | 1.7kb | 2022-09-22 15:56:41 | 2022-09-22 15:56:44 |
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 () {
freopen ("in.in", "r", stdin);
freopen ("out.out", "w", stdout);
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 = 1, 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;
}
詳細信息
Test #1:
score: 0
Dangerous Syscalls
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...