QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#49555 | #4412. Boss Rush | Winner | WA | 862ms | 30892kb | C++11 | 2.5kb | 2022-09-21 23:16:27 | 2022-09-21 23:16:29 |
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], f[N];
bool dp[N];
int t[Q], len[Q];
vector<ll> node[20];
struct LINE{
int l, r;
ll sum;
}line[N];
bool cmp(int x, int y){
return len[x] - t[x] > len[y] - t[y];
}
bool findans(int i, int x, int y, int mid){
int asd = min((int)node[y].size(), mid - line[x].l);
f[i] = max(f[i], f[x] + sum[y][asd]);
return f[i] >= H;
}
bool findlen(int x, int mid){
// cout << "x : " <<x << " " << line[x].r << endl;
return line[x].r <= mid;
}
bool check(int mid){
for(int i = 0; i < 1 << n; i++){
dp[i] = false;
f[i] = 0;
}
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(i, res, j + 1, mid)) return true;
if(findlen(i, mid)) dp[i] = true;
}
}
}
return false;
}
void init(){
for(int xx = 0; xx < 1 << n; xx++){
int x = xx;
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];
}
line[xx] = {l, r, res};
}
}
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;
}
}
init();
int ans = -1;
int l = 1, r = 10;
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
Wrong Answer
time: 862ms
memory: 30892kb
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:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer 1st lines differ - expected: '368', found: '-1'