QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#633979#7743. Grand FinaleGalexWA 96ms64736kbC++232.5kb2024-10-12 16:30:462024-10-12 16:30:47

Judging History

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

  • [2024-10-12 16:30:47]
  • 评测
  • 测评结果:WA
  • 用时:96ms
  • 内存:64736kb
  • [2024-10-12 16:30:46]
  • 提交

answer

#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define pii pair<int, int>
#define fi first
#define se second
#define mkp make_pair
#define sz(x) (int)x.size()
using namespace std;
bool Mst;

LL read() {
	LL s = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9')
		s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return s * f;
}

const int MAXN = 2505;

int trans(char c) {
	if (c == 'B') return 2;
	if (c == 'Q') return 1;
	if (c == 'W') return 0;
	return -1;
}

int n, m;
char s[MAXN], t[MAXN];
int cnt[3], a[MAXN];
bool g[MAXN][MAXN << 1];
int f[MAXN][MAXN << 1];

void work() {
	n = read(), m = read();
	scanf("%s\n%s", s + 1, t + 1);
	cnt[0] = cnt[1] = cnt[2] = 0;
	for (int i = 1; i <= n; i++)
		if (s[i] != 'G') cnt[trans(s[i])]++;
//	cout << cnt[0] << ' ' << cnt[1] << ' ' << cnt[2] << endl;
	for (int i = 1; i <= m; i++)
		a[i] = trans(t[i]);
	n--, a[m + 1] = -1;
	for (int i = 1; i <= m + 1; i++)
		for (int j = 0; j <= n + m; j++) g[i][j] = 0;
	g[1][cnt[2]] = 1;
	for (int i = 1, t[3] = {0}; i <= m; t[a[i++]]++)
		for (int j = 0; j <= cnt[2] + t[2]; j++) {
			int c1 = t[1] + cnt[1] - (i - 1 - (t[2] + cnt[2] - j) * 2);
			if (c1 < 0 || c1 > t[1] + cnt[1] || !g[i][j]) continue;
			if (j) g[min(m + 1, i + 2)][j - 1 + (a[i] == 2) + (a[i + 1] == 2)] = 1;
			if (c1) g[i + 1][j + (a[i] == 2)] = 1;
		}
	for (int i = 1; i <= m + 1; i++)
		for (int j = 0; j <= n + m; j++) f[i][j] = 1e9;
	for (int j = 0; j <= n + m; j++) f[m + 1][j] = 0;
	for (int i = m; i; i--)
		for (int j = 0; j <= n + m; j++) {
			f[i][j] = f[i + 1][j + (a[i] == 2)] - (a[i] == 1) + 1;
			if (j) f[i][j] = min(f[i][j], f[min(m + 1, i + 2)][j - 1 + (a[i] == 2)] - (a[i] == 1));
			f[i][j] = max(f[i][j], 0);
		}
//	cout << g[3][1] << ' ' << f[3][1] << endl;
	for (int k = n; k <= n + m; k++) {
		for (int i = 1, t[3] = {0}; i <= m + 1; t[a[i++]]++) {
			int c2 = cnt[2] + t[2] - (k - n), c1 = cnt[1] + t[1] - (i - 1 - (k - n) * 2);
//			if (k == n + 1 && i == 3) cout << c1 << ' ' << c2 << endl;
			if (c2 >= 0 && c2 <= cnt[2] + t[2] && c1 >= 0 && c1 <= cnt[1] + t[1] && g[i][c2] && f[i][c2] <= c1) {
//				cout << k << ' ' << i << ' ' << g[i][c2] << ' ' << c1 << ' ' << c2 << ' ' << f[i][c2] << endl;
				printf("%d\n", k + 1);
				return ;
			}
		}
	}
	printf("IMPOSSIBLE\n");
}

bool Med;
signed main() {
	fprintf(stderr, "%.2lfMB\n", abs(&Med - &Mst) / 1048576.0);
	int T = read();
	while (T--)
		work();
	return 0;
}

詳細信息

Test #1:

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

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

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 96ms
memory: 64736kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

184
372
314
161
118
534
IMPOSSIBLE
631
183
275
33
160
643

result:

wrong answer 3rd lines differ - expected: '316', found: '314'