QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#358557 | #7743. Grand Finale | Baiyu0123 | WA | 1ms | 3584kb | C++14 | 1.7kb | 2024-03-19 21:03:48 | 2024-03-19 21:03:49 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
#define mkp make_pair
#define pii pair<int,int>
#define ll long long
using namespace std;
const int maxn=2e5+100;
string s0,s;
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T;cin>>T;
while (T--) {
int n,m,k;
cin>>n>>m;
cin>>s0>>s;
for (k=n;k<=n+m;k++) {
int c1=0,c2=0,j=0,nk=n;
for (int i=0;i<s0.size();i++) c1+=(s[i]=='Q'),c2=(s[i]=='B');
for (;nk<k&&j<s.size();) {
if (c2) {
c2--;nk++;
c1+=(s[j]=='W'),c2=(s[j]=='B');j++;if (j==s.size()) break;
c1+=(s[j]=='W'),c2=(s[j]=='B');j++;if (j==s.size()) break;
continue;
}
if (c1) {
c1--;
c1+=(s[j]=='W'),c2=(s[j]=='B');j++;if (j==s.size()) break;
continue;
}
break;
}
// cout<<k<<" "<<j<<endl;
if (j!=s.size()&&c1==0&&c2==0) {
cout<<"impossible\n";
break;
}
if (nk!=k) {
cout<<k<<endl;
break;
}
for (;j<s.size();) {
if (j+1<s.size()&&c2&&s[j+1]=='W') {
c2--;
c1+=(s[j]=='W'),c2=(s[j]=='B');j++;if (j==s.size()) break;
j++;if (j==s.size()) break;
continue;
}
if (c1) {
c1--;
c1+=(s[j]=='W'),c2=(s[j]=='B');j++;if (j==s.size()) break;
continue;
}
if (c2) {
c2--;
c1+=(s[j]=='W'),c2=(s[j]=='B');j++;if (j==s.size()) break;
j++;if (j==s.size()) break;
continue;
}
break;
}
if (j==s.size()) {
cout<<k<<endl;
break;
}
}
if (k==n+m+1) {
cout<<"impossible\n";
}
}
}
/*
2
4 6
1 1 8
7 2 5
1 1 7
3 2 6
8 1200000
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3584kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
3 impossible
result:
wrong answer 2nd lines differ - expected: 'IMPOSSIBLE', found: 'impossible'