QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#548176 | #7743. Grand Finale | Bird# | WA | 0ms | 3768kb | C++14 | 956b | 2024-09-05 16:14:02 | 2024-09-05 16:14:02 |
Judging History
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'