QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#641473#7743. Grand Finalelllei#WA 523ms89524kbC++202.3kb2024-10-14 20:40:362024-10-14 20:40:37

Judging History

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

  • [2024-10-14 20:40:37]
  • 评测
  • 测评结果:WA
  • 用时:523ms
  • 内存:89524kb
  • [2024-10-14 20:40:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
int n, m;
int q, b;
int dp1[maxn][maxn];
int sumq[maxn], sumb[maxn];
string c;
int dfs1(int x, int y)
{
    if (x >= m)
        return 0;
    if (dp1[x][y] != -1)
        return dp1[x][y];
    int ans = 1e9;
    int tmp = dfs1(x + 1, y + (c[x + 1] == 'B')) + 1 - (c[x + 1] == 'Q');
    ans = min(ans, tmp == 0 ? 1 : dfs1(x + 1, y + (c[x + 1] == 'B')) + 1 - (c[x + 1] == 'Q'));
    if (y)
        ans = min(ans, dfs1(x + 2, y - 1 + (c[x + 1] == 'B')) - (c[x + 1] == 'Q'));
    return dp1[x][y] = ans;
}
/*
1
2 6
BG
BQWBWW
*/
int dp2[maxn][maxn];
void dfs2(int x, int y)
{
    if (dp2[x][y])
        return;
    dp2[x][y] = 1;
    if (x >= m)
        return;
    int curq = sumq[x] + q - (x - (sumb[x] + b - y) * 2);
    if (curq > 0)
        dfs2(x + 1, y + (c[x + 1] == 'B'));
    if (y > 0)
        dfs2(x + 2, y - 1 + (c[x + 1] == 'B') + (c[x + 2] == 'B'));
}
int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        b = q = 0;
        cin >> n >> m;
        cin >> c;
        for (int i = 0; i < n; i++)
        {
            if (c[i] == 'B')
                b++;
            else if (c[i] == 'Q')
                q++;
        }
        cin >> c;
        c = '#' + c + ' ';
        for (int i = 1; i <= m; i++)
        {
            sumb[i] = sumb[i - 1] + (c[i] == 'B');
            sumq[i] = sumq[i - 1] + (c[i] == 'Q');
        }
        for (int i = 0; i <= m; i++)
            for (int j = 0; j <= m + n; j++)
                dp1[i][j] = -1, dp2[i][j] = 0;
        dfs2(0, b);
        int ans = -1;
        for (int k = n; k <= m + n; k++)
        {
            for (int i = 2 * (k - n); i <= m; i++)
            {
                if (sumb[i] + b - (k - n) < 0 || sumq[i] + q - (i - 2 * (k - n)) < 0)
                    continue;
                if (dfs1(i, sumb[i] + b - (k - n)) <= sumq[i] + q - (i - 2 * (k - n)) && dp2[i][sumb[i] + b - (k - n)])
                {
                    ans = k;
                    break;
                }
            }
            if (ans != -1)
                break;
        }
        if (ans == -1)
            cout << "IMPOSSIBLE\n";
        else
            cout << ans << '\n';
    }
}

詳細信息

Test #1:

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

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

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 523ms
memory: 89524kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

184
372
316
161
118
527
IMPOSSIBLE
631
182
275
33
160
642

result:

wrong answer 6th lines differ - expected: '534', found: '527'