QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#42775 | #4412. Boss Rush | 01shijian# | WA | 2287ms | 10368kb | C++17 | 2.0kb | 2022-08-03 18:26:07 | 2022-08-03 18:26:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include <debugger>
clock_t start = clock();
#else
#define debug(...) 42
#endif
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
void solve() {
int n; ll H; cin >> n >> H;
vector<vector<int> > a(n);
vector<int> t(n);
ll sum = 0;
for(int i = 0; i < n; i ++ ) {
cin >> t[i];
int len; cin >> len;
a[i].resize(len + 1);
for(int j = 1; j <= len; j ++ ) {
cin >> a[i][j];
sum += a[i][j];
a[i][j] += a[i][j - 1];
}
}
if(sum < H) {
cout << "-1\n";
return;
}
auto check = [&] (ll x) -> bool {
// vector<vector<int> > f(1 << n, vector<int>(n));
vector<ll> f(1 << n);
for(int i = 0; i < 1 << n; i ++ ) {
int cnt = 0;
for(int j = 0; j < n; j ++ ) if(i >> j & 1) {
cnt += t[j];
}
if(cnt > x) continue;
for(int j = 0; j < n; j ++ ) if(not(i >> j & 1)) {
// chkmax(f[i ^ (1 << j)], f[i] + (x - cnt + 1 >= t[j] ? a[j].back() : a[j][x - cnt + 1]));
ll ret = f[i];
if(x - cnt + 1 >= a[j].size()) {
ret += a[j].back();
} else {
ret += a[j][x - cnt + 1];
}
// debug(i ^ (1 << j), ret);
if(ret >= H) return true;
chkmax(f[i ^ (1 << j)], ret);
}
}
// debug(*max_element(f.begin(), f.end()));
return *max_element(f.begin(), f.end()) >= H;
};
ll l = 0, r = 1800001;
while(l < r) {
ll mid = (l + r) / 2;
if(check(mid)) r = mid;
else l = mid + 1;
}
cout << l << "\n";
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T; cin >> T;
while(T -- )
solve();
#ifdef LOCAL
clock_t ends = clock();
// cout << "\n\nRunning Time : " << (double) (ends - start) / CLOCKS_PER_SEC * 1000 << "ms" << endl;
#endif
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2287ms
memory: 10368kb
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:
1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800001 1800...
result:
wrong answer 1st lines differ - expected: '368', found: '1800001'