QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269162 | #7743. Grand Finale | mendicillin2# | WA | 1ms | 3400kb | C++17 | 1.4kb | 2023-11-29 13:30:54 | 2023-11-29 13:30:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=2500+5;
int n,m;
char c1[N],c2[N];
inline bool check(int x)
{
int cnt=0;
int cnt1=0, cnt2=0;
for(int i=1;i<=n;i++)
if(c1[i]=='G' || c1[i]=='W')
cnt++;
else if(c1[i]=='Q') cnt1++;
else if(c1[i]=='B') cnt2++;
x-=cnt;
//cout<<cnt1<<" "<<cnt2<<" "<<"yes"<<endl;
for(int i=1;i<=m;i++)
{
//if(x==3) printf("i=%d cnt1=%d cnt2=%d\n",i,cnt1,cnt2);
if(i==m) return cnt1 || cnt2;
if(cnt1+cnt2+1<=x && cnt2)
{
cnt2--;
if(c2[i]=='W') x--;
else if(c2[i]=='Q') cnt1++;
else if(c2[i]=='B') cnt2++;
if(c2[i+1]=='W') x--;
else if(c2[i+1]=='Q') cnt1++;
else if(c2[i+1]=='B') cnt2++;
i=i+1;
continue;
}
if(cnt1+cnt2==x && cnt2 && c2[i+1]=='W')
{
cnt2--;
if(c2[i]=='W') x--;
else if(c2[i]=='Q') cnt1++;
else if(c2[i]=='B') cnt2++;
i=i+1;
}
else if(cnt1)
{
cnt1--;
if(c2[i]=='W') x--;
else if(c2[i]=='Q') cnt1++;
else if(c2[i]=='B') cnt2++;
}
else return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int T;
cin>>T;
while(T--)
{
cin>>n>>m;
cin>>c1+1;
cin>>c2+1;
int lef=n, rig=n+m;
while(lef<rig)
{
int mid=(lef+rig)>>1;
if(check(mid)) rig=mid;
else lef=mid+1;
}
//cout<<check(3)<<" "<<"qweqwq"<<endl;
if(check(lef)) cout<<lef<<"\n";
else cout<<"IMPOSSIBLE"<<"\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3364kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
3 IMPOSSIBLE
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3400kb
input:
2 3 8 QBG BBBWBWWW 3 8 QBG BBBWBWWW
output:
4 4
result:
wrong answer 1st lines differ - expected: '3', found: '4'