QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#358574 | #7743. Grand Finale | Baiyu0123 | WA | 1ms | 3652kb | C++14 | 1.8kb | 2024-03-19 21:10:34 | 2024-03-19 21:10:34 |
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+=(s0[i]=='Q'),c2+=(s0[i]=='B');
for (;nk<k&&j<s.size();) {
if (c2) {
c2--;nk++;
c1+=(s[j]=='Q'),c2+=(s[j]=='B');j++;if (j==s.size()) break;
c1+=(s[j]=='Q'),c2+=(s[j]=='B');j++;if (j==s.size()) break;
continue;
}
if (c1) {
c1--;
c1+=(s[j]=='Q'),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();) {
// cout<<j<<" "<<c1<<" "<<c2<<endl;
if (j+1<s.size()&&c2&&s[j+1]=='W') {
c2--;
c1+=(s[j]=='Q'),c2+=(s[j]=='B');j++;if (j==s.size()) break;
j++;if (j==s.size()) break;
continue;
}
if (c1) {
c1--;
c1+=(s[j]=='Q'),c2+=(s[j]=='B');j++;if (j==s.size()) break;
continue;
}
if (c2) {
c2--;
c1+=(s[j]=='Q'),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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3652kb
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: 3648kb
input:
2 3 8 QBG BBBWBWWW 3 8 QBG BBBWBWWW
output:
4 4
result:
wrong answer 1st lines differ - expected: '3', found: '4'