QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#732030 | #9599. Dragon Bloodline | yzhx | WA | 0ms | 3588kb | C++20 | 1.9kb | 2024-11-10 12:47:18 | 2024-11-10 12:47:18 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long
const int N = 5e4 + 10;
int n, k, a[N], b[35], c[35], d[35];
bool check(int mid) {
for(int i = 0; i <= 25; i ++ ) c[i] = 0;
for(int i = 0; i <= 25; i ++ ) d[i] = b[i];
priority_queue<int> q;
for(int i = 1; i <= n ; i ++ ) {
int x = mid * a[i];
q.push(x);
}
for(int i = 10; ~i ; i -- ) {
if(q.size() && q.top() <= (1 << i) && d[i]) {
q.pop();
d[i] -- ;
}
while(q.size() && q.top() >= (1 << i) && d[i]) {
int t = q.top();
int tt = t / (1 << i);
int ttt = min(tt, d[i]);
tt -= ttt, d[i] -= ttt;
q.pop();
if(t - ttt * (1 << i) == 0) continue;
q.push(t - ttt * (1 << i));
}
while(q.size() && q.top() <= (1 << i) && d[i]) {
q.pop();
d[i] -- ;
}
}
int j = 10;
while(q.size()) {
if(j <= 0) break;
while(j >= 0 && !d[j]) j -- ;
while(q.size() && j >= 0 && (1 << j) > q.top() && d[j]) {
if(j < 0) break;
d[j] -- ;
q.pop();
}
j -- ;
}
if(q.size()) return false;
return true;
}
void solve() {
cin >> n >> k;
memset(b, 0, sizeof b);
int per = 0, sum = 0;
for(int i = 1; i <= n ; i ++ ) cin >> a[i], per += a[i];
for(int i = 0; i < k ; i ++ ) cin >> b[i], sum += (1 << i) * b[i];
int l = 0, r = sum / per;
while(l < r) {
int mid = l + r + 1 >> 1;
if(check(mid)) l = mid;
else r = mid - 1;
}
cout << l << endl;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int T = 1;
cin >> T;
while(T -- ) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
6 4 3 1 2 3 4 4 4 4 3 2 1 1 1 1 7 3 4 6 6 2 1 1 5 5 3 5 3 1 1 1 1 1 1 1 4 5 1 9 9 8 2 2 2 3 1 5 4 1 3 1 7 1 4 1 5 2
output:
2 4 4 5 2 3
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3484kb
input:
1 1 20 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
2047000000000
result:
wrong answer 1st lines differ - expected: '1048575000000000', found: '2047000000000'