QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#271435 | #7743. Grand Finale | iorit# | WA | 0ms | 3856kb | C++14 | 1.1kb | 2023-12-02 12:15:50 | 2023-12-02 12:15:50 |
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,cnt;
char s[N],t[N],a[N];
bool check(int mid)
{
int B = 0;
for(int i = 1;i <= n;i++)
B += a[i] == 'B';
int r = n,tot = 0;
while(r < cnt)
{
if(tot == mid || !B)
return 0;
--B;
B += a[r + 1] == 'B';
if(r + 2 <= cnt)
B += a[r + 2] == 'B';
r += 2,++tot;
}
return 1;
}
int main()
{
cin >> ct;
while(ct--)
{
scanf("%d%d" , &n , &m);
scanf("%s%s" , s + 1 , t + 1),cnt = 0;
for(int i = 1;i <= n;i++)
if(s[i] != 'Q')
a[++cnt] = s[i];
for(int i = 1;i <= m;i++)
if(t[i] != 'Q')
a[++cnt] = t[i];
int l = n,r = cnt,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: 3672kb
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: 3856kb
input:
2 3 8 QBG BBBWBWWW 3 8 QBG BBBWBWWW
output:
4 4
result:
wrong answer 1st lines differ - expected: '3', found: '4'