QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#616913 | #7743. Grand Finale | REN5511 | WA | 0ms | 3616kb | C++14 | 1.9kb | 2024-10-06 13:00:37 | 2024-10-06 13:00:37 |
Judging History
answer
#include <iostream>
using namespace std;
int n, m;
int iniq=0, inib = 0;
char hand[2500 + 100], library[2500 + 100];
bool check(int mid) {
int draw=0,now = 1,q=iniq,b=inib;
int nowhand = n;
//draw = min(mid - nowhand, b) + b + q;
//nowhand += min(mid - nowhand, b);
draw = b + b + q;
nowhand += min(mid - nowhand, b);
while (draw > 0) {
q = 0;
b = 0;
int drop = max(b - (mid - nowhand), 0);
if (now + draw-1 >= m) {
return 1;
}
for (int i = now; i <= now + draw-1; i++) {
if (i != now && drop > 0&& library[i] == 'W') {
drop--;
}
if (library[i] == 'Q') {
q++;
}
if (library[i] == 'B') {
b++;
}
}
int cost = min(drop, q);
drop -= cost;
q -= cost;
cost = min(drop, b);
drop -= cost;
b -= cost;
now = now + draw;
draw = b + b + q;
nowhand += min(mid - nowhand, b);
}
return 0;
}
int findans(int l, int r) {
int ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
return ans;
}
void solve() {
iniq = 0; inib = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> hand[i];
if (hand[i] == 'Q') {
iniq++;
}
if (hand[i] == 'B') {
inib++;
}
}
for (int i = 1; i <= m; i++) {
cin >> library[i];
}
int ans = findans(n, 3000);
if (ans==-1) {
cout << "IMPOSSIBLE" << "\n";
}
else {
cout << ans<<"\n";
}
}
int main()
{
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
2 IMPOSSIBLE
result:
wrong answer 1st lines differ - expected: '3', found: '2'