QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#242076#7743. Grand FinaletriccsrWA 28ms50984kbC++203.3kb2023-11-06 22:15:352023-11-06 22:15:36

Judging History

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

  • [2023-11-06 22:15:36]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:50984kb
  • [2023-11-06 22:15:35]
  • 提交

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){
        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);
                }
            }
            {
                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));
                }
                if(a[i+1]=='W'){
                    d[i][j]=min(d[i][j],max(d[i+1][j]+1,2));
                }
            }
            d[i][j]=max(d[i][j],j);
            // 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<i+m)break;
            if(num_b>=k-m){
                int actual_b=num_b-(k-m);
                int actual_q=k-2-num_w-actual_b;
                if(actual_b>=0&&actual_q>=0&&actual_q<=num_q){
                    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5712kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 28ms
memory: 50984kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

184
IMPOSSIBLE
313
161
118
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
IMPOSSIBLE
33
160
IMPOSSIBLE

result:

wrong answer 2nd lines differ - expected: '372', found: 'IMPOSSIBLE'