QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#49542 | #4412. Boss Rush | Winner | TL | 0ms | 0kb | C++11 | 2.3kb | 2022-09-21 21:53:18 | 2022-09-21 21:53:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1 << 18;
const int inf = 3e6;
int T, n;
ll H, sum[N];
bool dp[N];
int t[N], len[N];
vector<ll> node[N];
bool cmp(int x, int y){
return len[x] - t[x] > len[y] - t[y];
}
bool findans(int x, int y, int mid){
ll res = 0;
vector<int> id;
int qwe = 1;
while(x){
if(x & 1){
id.push_back(qwe);
res += sum[qwe];
}
x >>= 1;
qwe++;
}
sort(id.begin(), id.end(), cmp);
int l = 0, r = 0;
for(auto it: id){
r = max(r, l + len[it]);
l += t[it];
}
for(int i = 0; i < node[y].size(); i++){
if(l + i + 1 <= mid){
res += node[y][i];
}
else break;
}
return res >= H;
}
bool findlen(int x, int mid){
vector<int> id;
int qwe = 1;
while(x){
if(x & 1) id.push_back(qwe);
x >>= 1;
qwe++;
}
sort(id.begin(), id.end(), cmp);
int l = 0, r = 0;
for(auto it: id){
r = max(r, l + len[it]);
l += t[it];
}
return r <= mid;
}
bool check(int mid){
memset(dp, 0, sizeof dp);
dp[0] = true;
for(int i = 1; i < 1 << n; i++){
for(int j = 0; j < n; j++){
if(i >> j & 1){
int res = i ^ (1 << j);
if(!dp[res]) continue;
if(findans(res, j + 1, mid)) return true;
if(findlen(i, mid)) dp[i] = true;
}
}
}
return false;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> T;
while(T--){
cin >> n >> H;
for(int i = 1; i <= n; i++){
node[i].clear();
sum[i] = 0;
cin >> t[i] >> len[i];
for(int j = 1; j <= len[i]; j++){
ll x;
cin >> x;
node[i].push_back(x);
sum[i] += x;
}
}
int ans = -1;
int l = 1, r = inf;
while(l <= r){
int mid = (l + r) / 2;
if(check(mid)){
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
if(ans != - 1) ans --;
cout << ans << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
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:
375 579 628 249 425 400 296 687 321 579 509 594 475 538 367 694 390 471 524 138 194 292 362 181 357 210 84 190 433 288 241 245 378 426 326 255 140 171 288 138 383 293 135 195 356 129 279 212 173 286 438 153 574 335 421 457 213 315 278 421 285 496 336 385 500 451 300 442 333 433 137 289 329 412 200 1...