QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#271445 | #7743. Grand Finale | iorit# | WA | 0ms | 3852kb | C++14 | 1.1kb | 2023-12-02 12:28:01 | 2023-12-02 12:28:01 |
Judging History
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'