QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#58712 | #4412. Boss Rush | qinjianbin | WA | 2106ms | 18744kb | C++17 | 1.2kb | 2022-10-27 15:07:24 | 2022-10-27 15:07:27 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
typedef long long ll;
const int N = 20;
int t[N], len[N], n;
ll k[1 << 18], dp[1 << 18];
vector<ll> s[N];
ll H, sum;
bool check(int key)
{
memset(dp, 0, sizeof dp);
rep(S, 0, 1 << n)
rep(i, 0, n)
if(S & (1 << i))
{
int temp = max(key - k[S ^ (1 << i)], 0ll);
dp[S] = max(dp[S], dp[S ^ (1 << i)] + s[i + 1][min(temp, len[i + 1])]);
if(dp[S] >= H) return true;
}
return false;
}
int main()
{
int T; scanf("%d", &T);
while(T--)
{
scanf("%d%lld", &n, &H);
_for(i, 1, n) s[i].clear();
sum = 0;
_for(i, 1, n)
{
scanf("%d%d", &t[i], &len[i]);
s[i].push_back(0);
_for(j, 1, len[i])
{
int x; scanf("%d", &x);
s[i].push_back(x + s[i].back());
sum += x;
}
}
if(sum < H)
{
puts("-1");
continue;
}
rep(S, 0, 1 << n)
{
k[S] = 0;
rep(i, 0, n)
if(S & (1 << i))
k[S] += t[i + 1] + 1;
k[S]--;
}
int l = -1, r = 3e6;
while(l + 1 < r)
{
int m = l + r >> 1;
if(check(m)) r = m;
else l = m;
}
printf("%d\n", r);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2106ms
memory: 18744kb
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:
374 587 636 253 431 404 300 696 326 587 516 601 482 546 372 703 395 477 530 144 199 298 368 187 363 217 75 195 442 293 245 251 385 434 334 261 139 177 295 142 391 298 139 199 363 135 284 217 173 293 447 158 583 342 429 466 218 319 282 427 289 503 341 390 506 457 304 448 337 439 131 293 333 418 202 1...
result:
wrong answer 1st lines differ - expected: '368', found: '374'