QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#248203 | #7743. Grand Finale | Redcrown# | WA | 0ms | 3828kb | C++17 | 1.6kb | 2023-11-11 17:52:01 | 2023-11-11 17:52:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
char str1[N],str2[N];
void cg(int &idx, int &nowb, int &nowq)
{
if(str2[idx] == 'B') nowb ++;
if(str2[idx] == 'Q') nowq ++;
idx ++;
}
void solve()
{
int n,m,i,bnum=0,qnum=0,now,nowb,nowq,nown;
scanf("%d%d",&n,&m);
scanf("%s%s",str1+1,str2+1);
for(i=1;i<=n;i++)
{
if(str1[i] == 'B') bnum ++;
if(str1[i] == 'Q') qnum ++;
}
for(i=n;i<=n+m;i++)
{
nowb = bnum; nowq = qnum; now = 1; nown = n;
while(now <= m && nown < i)
{
if(nowb)
{
nown ++; nowb --;
cg(now,nowb,nowq);
cg(now,nowb,nowq);
}
else if(nowq)
{
nowq --;
cg(now,nowb,nowq);
}
else break;
}
if(nown < i && now <= m) break;
while(now <= m)
{
if(!nowq && !nowb) break;
if(now+1 > m)
{
now ++; break;
}
if(!nowq || (str2[now+1] == 'W' && nowb))
{
nowb --;
cg(now,nowb,nowq);
now ++;
}
else
{
nowq --;
cg(now,nowb,nowq);
}
}
if(now > m)
{
printf("%d\n",i); return;
}
}
printf("IMPOSSIBLE\n");
}
int main()
{
int T=1;
scanf("%d",&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: 3828kb
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: 3772kb
input:
2 3 8 QBG BBBWBWWW 3 8 QBG BBBWBWWW
output:
4 4
result:
wrong answer 1st lines differ - expected: '3', found: '4'