QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#616913#7743. Grand FinaleREN5511WA 0ms3616kbC++141.9kb2024-10-06 13:00:372024-10-06 13:00:37

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 13:00:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-10-06 13:00:37]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'