QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269162#7743. Grand Finalemendicillin2#WA 1ms3400kbC++171.4kb2023-11-29 13:30:542023-11-29 13:30:56

Judging History

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

  • [2023-11-29 13:30:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3400kb
  • [2023-11-29 13:30:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N=2500+5;
int n,m;
char c1[N],c2[N];

inline bool check(int x)
{
	int cnt=0;
	int cnt1=0, cnt2=0;
	for(int i=1;i<=n;i++) 
		if(c1[i]=='G' || c1[i]=='W') 
			cnt++;
		else if(c1[i]=='Q') cnt1++;
		else if(c1[i]=='B') cnt2++;
	x-=cnt;
	//cout<<cnt1<<" "<<cnt2<<" "<<"yes"<<endl;
	for(int i=1;i<=m;i++)
	{
		//if(x==3) printf("i=%d cnt1=%d cnt2=%d\n",i,cnt1,cnt2);
		if(i==m) return cnt1 || cnt2;
		if(cnt1+cnt2+1<=x && cnt2)
		{
			cnt2--;

			if(c2[i]=='W') x--;
			else if(c2[i]=='Q') cnt1++;
			else if(c2[i]=='B') cnt2++;

			if(c2[i+1]=='W') x--;
			else if(c2[i+1]=='Q') cnt1++;
			else if(c2[i+1]=='B') cnt2++;

			i=i+1;
			continue;
		}
		if(cnt1+cnt2==x && cnt2 && c2[i+1]=='W')
		{
			cnt2--;
			if(c2[i]=='W') x--;
			else if(c2[i]=='Q') cnt1++;
			else if(c2[i]=='B') cnt2++;
			i=i+1;
		}
		else if(cnt1)
		{
			cnt1--;
			if(c2[i]=='W') x--;
			else if(c2[i]=='Q') cnt1++;
			else if(c2[i]=='B') cnt2++;
		}
		else return false;
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	{
		cin>>n>>m;
		cin>>c1+1;
		cin>>c2+1;
		int lef=n, rig=n+m;
		while(lef<rig)
		{
			int mid=(lef+rig)>>1;
			if(check(mid)) rig=mid;
			else lef=mid+1;
		}
		//cout<<check(3)<<" "<<"qweqwq"<<endl;
		if(check(lef)) cout<<lef<<"\n";
		else cout<<"IMPOSSIBLE"<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3400kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

4
4

result:

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