QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617064#7743. Grand FinaleREN5511WA 1ms3624kbC++143.9kb2024-10-06 13:45:472024-10-06 13:45:47

Judging History

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

  • [2024-10-06 13:45:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3624kb
  • [2024-10-06 13:45:47]
  • 提交

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);
    while (now <= m&& (b || q)) {
        if (now + 2 * b + q > m) {
            return 1;
        }
        if (nowhand < mid) {
            while (nowhand < mid&&(b||q)) {
                while (nowhand < mid&&b) {
                    b--;
                    nowhand++;
                    if (library[now] == 'Q') {
                        q++;
                    }
                    if (library[now] == 'B') {
                        b++;
                    }
                    if (library[now + 1] == 'Q') {
                        q++;
                    }
                    if (library[now + 1] == 'B') {
                        b++;
                    }
                    now += 2;
                    if (now > m) {
                        return 1;
                    }
                }
                while (nowhand < mid&&q&&(b<=0)) {
                    q--;
                    if (library[now] == 'Q') {
                        q++;
                    }
                    if (library[now] == 'B') {
                        b++;
                    }
                    now += 1;
                    if (now > m) {
                        return 1;
                    }
                }
            }
        }
        else {
            if (library[now] == 'B'&&b) {
                b--;
                if (library[now] == 'Q') {
                    q++;
                }
                if (library[now] == 'B') {
                    b++;
                }
                now += 2;
                if (now > m) {
                    return 1;
                }
            }
            else if (library[now] == 'Q' && q) {
                q--;
                if (library[now] == 'Q') {
                    q++;
                }
                if (library[now] == 'B') {
                    b++;
                }
                now += 1;
                if (now > m) {
                    return 1;
                }
            }
            else if (library[now + 1] != 'W'&&q>0) {
                q--;
                if (library[now] == 'Q') {
                    q++;
                }
                if (library[now] == 'B') {
                    b++;
                }
                now += 1;
                if (now > m) {
                    return 1;
                }

            }
            else {
                b--;
                if (library[now] == 'Q') {
                    q++;
                }
                if (library[now] == 'B') {
                    b++;
                }
                now += 2;
                if (now > m) {
                    return 1;
                }
            }
        }

    }
    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: 100
Accepted
time: 0ms
memory: 3592kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3536kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

199
89
205
162
130
156
IMPOSSIBLE
133
213
106
38
160
123

result:

wrong answer 1st lines differ - expected: '184', found: '199'