QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#548176#7743. Grand FinaleBird#WA 0ms3768kbC++14956b2024-09-05 16:14:022024-09-05 16:14:02

Judging History

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

  • [2024-09-05 16:14:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3768kb
  • [2024-09-05 16:14:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int t,n,m;
char a[2505],b[2505];
void add(char s,int &x,int &y){
	if(s=='Q') x++;
	if(s=='B') y++;
}
int chk(int k){
	int now=1,x=0,y=0,sum=n;
	for(int i=1;i<=n;i++) add(a[i],x,y);
	while(now<=m){
		if(sum<k&&y){
			y--;sum++;
			add(b[now++],x,y);
			add(b[now++],x,y);
		}
		else if(sum==k&&b[now+1]=='W'&&y){
			y--;
			add(b[now++],x,y);
			now++;
		}
		else if(x){
			x--;
			add(b[now++],x,y);
		}
		else if(y){
			y--;
			if(sum==k){
				add(b[now++],x,y);
				now++;
			}
			else{
				sum++;
				add(b[now++],x,y);
				add(b[now++],x,y);
			}
		}
		else return 0;
	}
	return 1;
}
void solve(){
	cin>>n>>m;
	scanf("%s",a+1);
	scanf("%s",b+1);
	int l=n,r=n+m+1;
	while(l<r){
		int mid=(l+r)/2;
		if(chk(mid)) r=mid;
		else l=mid+1;
	}
	if(l==n+m+1) puts("IMPOSSIBLE");
	else cout<<l<<endl;
}
int main(){
	cin>>t;
	while(t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

4
4

result:

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