QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#46045 | #4412. Boss Rush | miaomiaozi | RE | 0ms | 0kb | C++17 | 2.2kb | 2022-08-24 22:53:40 | 2022-08-24 22:53:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// https://space.bilibili.com/672346917
#ifndef LOCAL
#define LOG(...) 42
#endif
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long LL;
typedef pair <int, int> PII;
constexpr LL inf = 1e18;
constexpr double EPS = 1e-8;
const double PI = acos(-1);
int multi_cases = 1;
void A_SOUL_AvA () {
int n;
LL H;
cin >> n >> H;
vector d(n, vector<LL>(1));
vector t(n, 0), len(n, 0);
int l = 0, r = 0;
for (int i = 0; i < n; i++) {
int m;
cin >> t[i] >> m;
len[i] = m;
r += max(t[i], len[i]);
for (int j = 0; j < m; j++) {
int x;
cin >> x;
d[i].pb(x);
}
for (int j = 1; j < (int)d[i].size(); j++) {
d[i][j] += d[i][j - 1];
}
}
LL ans = inf;
auto chk = [&](int mid) -> bool {
vector <LL> f(1 << n, inf);
function <LL(int)> dfs = [&](int S) -> LL {
if (f[S] != inf) return f[S];
int tot_time = 0;
LL damage = 0;
for (int i = 0; i < n; i++) {
if (S >> i & 1) {
tot_time += t[i];
}
}
for (int i = 0; i < n; i++) {
if (S >> i & 1 ^ 1) {
LL now = d[i][min(len[i], mid - tot_time + 1)];
damage = max(damage, now + dfs(S | (1 << i)));
}
}
return f[S] = damage;
};
LL damage = dfs(0);
return damage >= H;
};
r = r * 2 + 10;
while (l < r) {
int mid = l + r >> 1;
if (chk(mid)) r = mid;
else l = mid + 1;
}
// cout << r << endl;
// cout << chk(6) << endl;
cout << (chk(r) ? r : -1) << endl;
}
int main () {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(12);
int T = 1;
for (multi_cases && cin >> T; T; T--) {
A_SOUL_AvA ();
}
return 0;
}
详细
Test #1:
score: 0
Runtime Error
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...