QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#246721#7743. Grand FinalecomeintocalmWA 30ms51320kbC++143.3kb2023-11-11 01:43:202023-11-11 01:43:21

Judging History

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

  • [2023-11-11 01:43:21]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:51320kb
  • [2023-11-11 01:43:20]
  • 提交

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],max(d[i+2][j-1],j));
                }
                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],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>=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: 100
Accepted
time: 0ms
memory: 3812kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5728kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 30ms
memory: 51320kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

184
372
316
161
118
534
570
631
183
276
33
160
643

result:

wrong answer 7th lines differ - expected: 'IMPOSSIBLE', found: '570'