QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246614 | #7743. Grand Finale | comeintocalm | WA | 0ms | 3844kb | C++14 | 3.4kb | 2023-11-10 23:08:03 | 2023-11-10 23:08:04 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#include<complex>
#include<assert.h>
#include<list>
#include <string>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define mid (x+y>>1)
#define lowbit(x) (x&(-x))
#define sqr(x) (1ll*(x)*(x))
#define NM 2505
#define nm 1000005
using namespace std;
const double pi=acos(-1);
const ll inf=1e9+7;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
int n,m;
int d[NM][NM*2];
int tot;
char a[NM],b[NM];
int solve(){
m=read();n=read();
scanf("%s",b+1);
scanf("%s",a+1);
tot=0;
inc(i,1,n)if(a[i]=='B')tot++;
inc(i,1,m)if(b[i]=='B')tot++;
inc(j,0,tot)d[n][j]=d[n+1][j]=j;
dec(i,n-1,0){
printf("%c\n",a[i+1]);
inc(j,0,tot){
d[i][j]=inf;
if(j>0){
if(a[i+1]=='Q'){
d[i][j]=min(d[i][j],d[i+2][j-1]);
}
if(a[i+1]=='B'){
d[i][j]=min(d[i][j],d[i+2][j]);
}
if(a[i+1]=='W'){
d[i][j]=min(d[i][j],d[i+2][j-1]+1);
}
}
d[i][j]=max(d[i][j],j);
{
if(a[i+1]=='Q'){
d[i][j]=min(d[i][j],max(d[i+1][j],j+1));
}
if(a[i+1]=='B'&&j<tot){
d[i][j]=min(d[i][j],max(d[i+1][j+1],j+1));
}
if(a[i+1]=='W'){
d[i][j]=min(d[i][j],max(d[i+1][j]+1,j+1));
}
}
printf("%d ",d[i][j]);
}
putchar('\n');
}
int init_b=0,init_q=0,init_w=0;
inc(i,1,m){
if(b[i]=='B')init_b++;
if(b[i]=='Q')init_q++;
if(b[i]=='W')init_w++;
}
// puts("--------");
if(d[0][init_b]<=init_b+init_q){
printf("%d\n",m);
return 0;
}
inc(k,m+1,n+m){
int num_b=init_b,num_q=init_q,num_w=init_w;
inc(i,0,n){
if(i>0){
if(a[i]=='B')num_b++;
if(a[i]=='Q')num_q++;
if(a[i]=='W')num_w++;
}
if(num_b*2+num_q+num_w+1<i+m)break;
if(num_b>=k-m){
int actual_b=num_b-(k-1-m);
int actual_q=k-2-num_w-actual_b;
if(actual_b>0&&actual_q>=0&&actual_q<=num_q){
actual_b--;
inc(j,i+1,i+2)if(j<=n){
if(a[j]=='B')actual_b++;
if(a[j]=='Q')actual_q++;
}
// printf("%d %d %d %d\n",k,i,actual_b,actual_q);
if(d[i+2][actual_b]<=actual_b+actual_q){
printf("%d\n",k);
return 0;
}
}
}
}
}
printf("IMPOSSIBLE\n");
return 0;
}
int main(){
int _=read();while(_--)solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3844kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
W 1 1 2 3 W 2 1 2 3 B 1 1 2 3 W 2 2 2 3 Q 2 1 2 3 B 1 2 2 3 3 B 1 1 2 Q 1 1 2 W 2 2 2 W 3 2 2 W 4 3 3 W 5 4 3 IMPOSSIBLE
result:
wrong answer 1st lines differ - expected: '3', found: 'W'