QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262267#7743. Grand Finaleucup-team2303#WA 51ms64196kbC++172.6kb2023-11-23 17:27:142023-11-23 17:27:15

Judging History

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

  • [2023-11-23 17:27:15]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:64196kb
  • [2023-11-23 17:27:14]
  • 提交

answer

/*
60 + 0 + 100 + 64 = 224.
*/

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define L(i, j, k) for (int i = (j); i <= (k); i++)
#define R(i, j, k) for (int i = (j); i >= (k); i--)
#define pb push_back
#define pii pair<int, int>
inline int read()
{
	int sum = 0, nega = 1;
	char ch = getchar();
	while (ch > '9'||ch < '0')
	{
	    if (ch == '-') nega = -1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
	return sum * nega;
}
const int N = 2509, mod = 998244353;
inline void add(int &x, int y) {x = (x + y) % mod;}
inline void del(int &x, int y) {x = (x - y + mod) % mod;}
int T, n, m, cb;
int nb[N], nq[N], B, Q;
char s[N], t[N];
int dp[N][N << 1];
bool f[N][N << 1];
inline int check(int x)
{
	if(x < n) return 0;
//	cout << f[2][x - n] << " " << x - n << endl;
	L(i, 0, m)
		if(f[i][x - n])
		{
//			cout << i << "awa" << endl;
			int wq = nq[i] + Q - (i - (x - n) * 2), wb = nb[i] + B - (x - n);
			if(dp[i + 1][wb] <= wq) return 1;
		}
	return 0;
}
inline void solve()
{
	n = read(), m = read(); cb = 0;
	B = Q = 0;
	scanf("%s", s + 1); scanf("%s", t + 1);
	L(i, 1, n) cb += (s[i] == 'B');
	L(i, 1, m) cb += (t[i] == 'B');
	L(i, 1, n)
	{
		if(s[i] == 'B') B++;
		else if(s[i] == 'Q') Q++;
	}
	L(i, 1, m)
	{
		if(t[i] == 'B') nb[i] = nb[i - 1] + 1;
		else nb[i] = nb[i - 1];
		if(t[i] == 'Q') nq[i] = nq[i - 1] + 1;
		else nq[i] = nq[i - 1];
	}
	L(i, 0, m)
		L(j, 0, n + m) dp[i][j] = 1e9, f[i][j] = 0;
	L(i, 0, n + m) dp[m][i] = 0; dp[m][0] = 1;
	L(i, 0, n + m) dp[m + 1][i] = 0;
	R(i, m - 1, 1)
	{
		L(j, 1, n + m)
		{
			if(t[i] == 'B') dp[i][j] = min(dp[i][j], dp[i + 2][j]);
			else if(t[i] == 'Q') dp[i][j] = min(dp[i][j], dp[i + 2][j - 1] + 1);
			else dp[i][j] = min(dp[i][j], dp[i + 2][j - 1]);
		}
		L(j, 0, n + m)
		{
			int nw = 1;
			if(t[i] == 'B') nw = max(nw, dp[i + 1][j + 1] + 1);
			else if(t[i] == 'Q') nw = max(nw, dp[i + 1][j]);
			else nw = max(nw, dp[i + 1][j] + 1);
			dp[i][j] = min(dp[i][j], nw);
		}
	}
	f[0][0] = 1;
	L(i, 0, m)
		L(j, 0, n + m)
		{
			if(!f[i][j]) continue;
			if(i - j * 2 < 0) continue;
			int wq = nq[i] + Q - (i - j * 2), wb = nb[i] + B - j;
			if(wq < 0 || wb < 0) continue;
			if(wq) f[i + 1][j] = 1;
			if(wb) f[i + 2][j + 1] = 1;
		}
//	cout << check(3) << endl; return ;
	int ans = 0;
	L(i, 1, n + m)
	{
		if(check(i)) {ans = i; break;}
	}
	if(ans) printf("%d\n", ans);
	else puts("IMPOSSIBLE"); return ;
}
signed main()
{
	T = read();
	L(i, 1, T) solve();
	return 0;
}


詳細信息

Test #1:

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

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

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 51ms
memory: 64196kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

240
508
654
161
214
723
IMPOSSIBLE
721
351
406
35
160
754

result:

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