QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#271445#7743. Grand Finaleiorit#WA 0ms3852kbC++141.1kb2023-12-02 12:28:012023-12-02 12:28:01

Judging History

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

  • [2023-12-02 12:28:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3852kb
  • [2023-12-02 12:28:01]
  • 提交

answer

#include <bits/stdc++.h>
#define LL long long
#define sl(n) strlen(n)
#define endline puts("")
#define pii pair<int , int>
#define pr_q priority_queue
#define DEBUG puts("DEBUG.")
using namespace std;
const int N = 1e5 + 10;
const int inf = ~0u >> 2;
int ct,n,m;
char s[N],t[N],a[N];
bool check(int mid)
{
	int B = 0,Q = 0;
	for(int i = 1;i <= n;i++)
		B += a[i] == 'B',Q += a[i] == 'Q';
	int r = n,tot = n;
	while(r < n + m && B + Q)
	{
		if(Q)
			++r,B += a[r] == 'B',Q += a[r] == 'Q',--Q;
		else
		{
			++r,B += a[r] == 'B',Q += a[r] == 'Q';
			++r;
			if(r <= n + m && tot < mid)
				B += a[r] == 'B',Q += a[r] == 'Q',++tot;
			--B;
		}
	}
	return r >= n + m && tot <= mid;
}
int main()
{
	cin >> ct;
	while(ct--)
	{
		scanf("%d%d" , &n , &m);
		scanf("%s%s" , s + 1 , t + 1);
		for(int i = 1;i <= n;i++)
			a[i] = s[i];
		for(int i = 1;i <= m;i++)
			a[i + n] = t[i];
		int l = n,r = n + m,res = -1;
		while(l <= r)
		{
			int mid = l + r >> 1;
			if( check(mid) )
				res = mid,r = mid - 1;
			else
				l = mid + 1;
		}
		if(~res)
			cout << res << endl;
		else
			puts("IMPOSSIBLE");
	}
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3816kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

4
4

result:

wrong answer 1st lines differ - expected: '3', found: '4'