QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#49546 | #4412. Boss Rush | Winner | TL | 0ms | 0kb | C++11 | 2.4kb | 2022-09-21 22:15:13 | 2022-09-21 22:15:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1 << 18;
const int M = 3e6;
const int Q = 1e5 + 20;
int T, n;
ll H, sum[20][Q];
bool dp[N];
int t[Q], len[Q];
vector<ll> node[20];
bool cmp(int x, int y){
return len[x] - t[x] > len[y] - t[y];
}
bool findans(int x, int y, ll mid){
ll res = 0;
vector<int> id;
int qwe = 1;
while(x){
if(x & 1){
id.push_back(qwe);
res += sum[qwe][0];
}
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];
}
int asd = min((ll)node[y].size() - 1, mid - l);
res += sum[y][asd];
return res >= H;
}
bool findlen(int x, ll 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){
for(int i = 0; i < 1 << n; i++){
dp[i] = false;
}
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] = sum[i][1] = 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][0] += x;
if(j == 1) sum[i][1] = x;
else sum[i][j] = sum[i][j - 1] + x;
}
}
int ans = -1;
int l = 1, r = M;
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;
}
詳細信息
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:
367 575 593 249 396 347 263 687 321 579 467 525 468 512 344 684 358 471 507 138 165 292 336 181 354 210 83 179 433 227 232 244 373 426 326 252 139 152 285 138 383 263 135 195 354 129 279 210 173 279 438 153 574 305 356 456 213 285 274 418 285 491 324 385 463 450 273 429 332 426 137 273 307 412 200 1...