QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#243829#7743. Grand FinaleHpSuda#WA 59ms26600kbC++173.1kb2023-11-08 17:57:052023-11-08 17:57:07

Judging History

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

  • [2023-11-08 17:57:07]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:26600kb
  • [2023-11-08 17:57:05]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
using ll = long long;

void solve() {
    int n, m;
    cin >> n >> m;
    string a, b;
    cin >> a >> b;
    vector<vector<int>> f(m + 2, vector<int>(m + 1, n + m + 1));
    for (int i = 0; i <= m; ++i) {
        f[m][i] = f[m+1][i] = 0;
    }
    for (int i = m - 1; i >= 0; i--) {
        int cur = 0;
        if (b[i] == 'B') cur = 2;
        else if (b[i] == 'Q') cur = 1;
        for (int j = 0; j <= m; j++) {
            if (!j) {
                if (cur == 1) {
                    f[i][j] = max(1, f[i + 1][j]);
                }
                else if (cur == 2) {
                    f[i][j] = max(1, f[i + 1][j + 1] + 1);
                }
                else {
                    f[i][j] = max(1, f[i+1][j] + 1);
                }
            }
            else {
                if (j * 2 >= m - i) {
                    f[i][j] = 0;
                }
                else {
                    if (cur == 1) {
                        f[i][j] = max(0, f[i + 2][j - 1] - 1);
                        f[i][j] = min(f[i][j], max(1, f[i + 1][j]));
                    }
                    else if (cur == 2) {
                        f[i][j] = f[i + 2][j];
                        f[i][j] = min(f[i][j], f[i + 1][j + 1] + 1);
                    }
                    else {
                        f[i][j] = f[i + 2][j - 1];
                        f[i][j] = min(f[i][j], f[i + 1][j] + 1);
                    }
                }
            }
        }
    }
    int c1 = 0, c2 = 0;
    int sum = n;
    for (int i = 0; i < n; i++) {
        if (a[i] == 'Q') ++c1;
        else if (a[i] == 'B') ++c2;
    }
    auto check = [&](int x) -> bool {
        sum = n;
        int cur = 0;
        int s1 = c1, s2 = c2;
        while (cur < m && sum < x) {
            if (s2) {
                s2--;
                if (b[cur] == 'B') {
                    s2++;
                }
                else if (b[cur] == 'Q') {
                    s1++;
                }
                sum++;
                cur++;
                if (cur == m) break;
                if (b[cur] == 'B') {
                    s2++;
                }
                else if (b[cur] == 'Q') {
                    s1++;
                }
            }
            else if (s1) {
                s1--;
                if (b[cur] == 'B') {
                    s2++;
                }
                else if (b[cur] == 'Q') {
                    s1++;
                }
                cur++;
            }
            else {
                break;
            }
        }
        if (cur == m) return true;
        if (!s1 && !s2) return false;
        if (s2 * 2 + s1 >= m - cur) return true;
        return f[cur][s2] <= s1;
    };
    for (int i = n; i <= n + m; i++) {
        if (check(i)) {
            cout << i << "\n";
            return;
        }
    }
    cout << "IMPOSSIBLE\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3460kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3420kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 59ms
memory: 26600kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

184
528
330
161
118
590
IMPOSSIBLE
951
197
356
33
160
934

result:

wrong answer 2nd lines differ - expected: '372', found: '528'