QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#286382#7743. Grand FinaleTsReaperWA 40ms27940kbC++172.4kb2023-12-17 19:38:482023-12-17 19:38:49

Judging History

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

  • [2023-12-17 19:38:49]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:27940kb
  • [2023-12-17 19:38:48]
  • 提交

answer

#include <bits/stdc++.h>
#define MAXN 2500
#define MAXM 2500
#define INF ((int) 1e9)
using namespace std;

int n, m;
char H[MAXN + 10], P[MAXM + 10];

int num[MAXM + 10][3], f[MAXM + 10][MAXM / 2 + 10];
bool g[MAXM + 10][MAXN + MAXM + 10];

int idx(char c) {
    if (c == 'Q') return 1;
    else if (c == 'B') return 2;
    else return 0;
}

int query(int i, int j) {
    if (j * 2 >= m - i) return 0;
    return f[i][j];
}

void solve() {
    scanf("%d%d%s%s", &n, &m, H + 1, P + 1);

    for (int i = 0; i < 3; i++) num[0][i] = 0;
    for (int i = 1; i <= n; i++) num[0][idx(H[i])]++;
    for (int i = 1; i <= m; i++) {
        for (int j = 0; j < 3; j++) num[i][j] = num[i - 1][j];
        num[i][idx(P[i])]++;
    }

    for (int i = m - 1; i >= 0; i--) for (int j = 0; j * 2 < m - i; j++) {
        f[i][j] = INF;

        if (P[i + 1] == 'Q') f[i][j] = min(f[i][j], max(query(i + 1, j), 1));
        else if (P[i + 1] == 'B') f[i][j] = min(f[i][j], query(i + 1, j + 1) + 1);
        else f[i][j] = min(f[i][j], query(i + 1, j) + 1);

        if (j == 0) continue;
        if (P[i + 2] == 'Q') f[i][j] = min(f[i][j], max(query(i + 2, j - 1) - 1, 0));
        else if (P[i + 2] == 'B') f[i][j] = min(f[i][j], query(i + 2, j));
        else f[i][j] = min(f[i][j], query(i + 2, j - 1));
    }

    for (int i = 0; i <= m; i++) for (int j = 0; j <= num[m][2]; j++) g[i][j] = false;
    g[0][num[0][2]] = true;
    for (int i = 0; i < m; i++) for (int j = 0; j <= num[i][2]; j++) if (g[i][j]) {
        int one = i - (num[i][2] - j) * 2;
        if (one < 0) continue;

        if (one > 0) {
            if (P[i + 1] == 'B') g[i + 1][j + 1] = true;
            else g[i + 1][j] = true;
        }

        if (j > 0 && i + 2 <= m) {
            int tmp = (P[i + 1] == 'B' ? 1 : 0) + (P[i + 2] == 'B' ? 1 : 0);
            g[i + 2][j - 1 + tmp] = true;
        }
    }

    for (int k = n; k <= n + m; k++) for (int t = 0; t <= m; t++) {
        int i = t + k - n;
        if (i < 0 || i > m) continue;
        int cnt1 = num[i][1] - t + k - n;
        int cnt2 = num[i][2] - k + n;
        if (cnt1 >= 0 && cnt2 >= 0 && query(i, cnt2) <= cnt1 && g[i][cnt2]) {
            printf("%d\n", k);
            return;
        }
    }
    printf("IMPOSSIBLE\n");
}

int main() {
    int tcase; scanf("%d", &tcase);
    while (tcase--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5972kb

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: 5984kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 40ms
memory: 27940kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

184
IMPOSSIBLE
316
161
118
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
183
IMPOSSIBLE
33
160
IMPOSSIBLE

result:

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