QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#248779#7743. Grand FinalecomeintocalmWA 1ms7720kbC++143.0kb2023-11-11 21:38:452023-11-11 21:38:45

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 21:38:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7720kb
  • [2023-11-11 21:38:45]
  • 提交

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];
bool g[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]=0;
    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],max(d[i+2][j-1]-1,0));
                }
                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]);
                }
            }
            {
                if(a[i+1]=='Q'){
                    d[i][j]=min(d[i][j],max(d[i+1][j],1));
                }
                if(a[i+1]=='B'&&j<tot){
                    d[i][j]=min(d[i][j],max(d[i+1][j+1]+1,1));
                }
                if(a[i+1]=='W'){
                    d[i][j]=min(d[i][j],max(d[i+1][j]+1,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_q){
        printf("%d\n",m);
        return 0;
    }
    int ans=inf;
    inc(i,0,n)inc(j,0,tot)g[i][j]=false;
    g[0][init_b]=true;
    inc(i,0,n-1){
        if(i>0){
            if(a[i]=='B')init_b++;
            if(a[i]=='Q')init_q++;
            if(a[i]=='W')init_w++;
        }
        inc(j,0,tot)if(g[i][j]){
            int num_b=j,num_q=init_q-(i-2*(init_b-j));
            if(d[i][j]<=num_q){
                ans=min(ans,init_w+1+num_b+num_q);
            }

            if(j>0&&i<n-1){
                g[i+2][j-1]=true;
            }
            if(num_q>0){
                g[i+1][j]=true;
            }
        }
    }
    if(ans<inf)printf("%d\n",ans);
    else printf("IMPOSSIBLE\n");
    return 0;
}

int main(){
    int _=read();while(_--)solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7720kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

4
IMPOSSIBLE

result:

wrong answer 1st lines differ - expected: '3', found: '4'