QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#616862#7743. Grand FinaleasaltfishWA 0ms3688kbC++231.5kb2024-10-06 12:39:212024-10-06 12:39:23

Judging History

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

  • [2024-10-06 12:39:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3688kb
  • [2024-10-06 12:39:21]
  • 提交

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;
    while (draw > 0) {
        q = 0;
        b = 0;
        if (now + draw >= m) {
            return 1;
        }
        for (int i = now; i <= now + draw; i++) {
            if (library[i] == 'Q') {
                q++;
            }
            if (library[i] == 'B') {
                b++;
            }
        }
        now = now + draw;
        draw = min(mid - nowhand, b) + b + q;
    }
    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 <= n; 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: 100
Accepted
time: 0ms
memory: 3628kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3688kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

4
IMPOSSIBLE

result:

wrong answer 1st lines differ - expected: '3', found: '4'