QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#394462#7743. Grand Finale2745518585WA 93ms51268kbC++202.3kb2024-04-20 14:56:442024-04-20 14:56:45

Judging History

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

  • [2024-04-20 14:56:45]
  • 评测
  • 测评结果:WA
  • 用时:93ms
  • 内存:51268kb
  • [2024-04-20 14:56:44]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=5001;
int n,m,a0[N],a1[N],a2[N],f[N][N],g[N][N];
char a[N];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&m,&n);
        {
            a0[0]=a1[0]=a2[0]=0;
            static char z[N];
            scanf("%s",z+1);
            for(int i=1;i<=m;++i)
            {
                if(z[i]=='W') ++a0[0];
                else if(z[i]=='Q') ++a1[0];
                else if(z[i]=='B') ++a2[0];
            }
            --m;
        }
        scanf("%s",a+1);
        for(int i=1;i<=n;++i)
        {
            a0[i]=a0[i-1],a1[i]=a1[i-1],a2[i]=a2[i-1];
            if(a[i]=='W') ++a0[i];
            else if(a[i]=='Q') ++a1[i];
            else if(a[i]=='B') ++a2[i];
        }
        for(int i=0;i<=n+2;++i)
        {
            for(int j=0;j<=a2[n]+1;++j) f[i][j]=-1e9;
        }
        f[0][a2[0]]=a1[0];
        for(int i=1;i<=n;++i)
        {
            for(int j=0;j<=a2[n];++j)
            {
                if(f[i-1][j-(a[i]=='B')]>0) f[i][j]=max(f[i][j],f[i-1][j-(a[i]=='B')]-1+(a[i]=='Q'));
                if(i>1&&j-(a[i-1]=='B')-(a[i]=='B')+1>0) f[i][j]=max(f[i][j],f[i-2][j-(a[i-1]=='B')-(a[i]=='B')+1]+(a[i-1]=='Q')+(a[i]=='Q'));
            }
        }
        for(int i=0;i<=n;++i)
        {
            for(int j=a2[n]-1;j>=0;--j) f[i][j]=max(f[i][j],f[i][j+1]);
        }
        for(int i=0;i<=n+2;++i)
        {
            for(int j=0;j<=a2[n]+1;++j) g[i][j]=1e9;
        }
        g[n+1][0]=g[n+2][0]=0;
        for(int i=n;i>=1;--i)
        {
            for(int j=0;j<=a2[n];++j)
            {
                g[i][j]=min(g[i][j],g[i+1][j+(a[i]=='B')]-(a[i]=='Q')+1);
                if(j>0) g[i][j]=min(g[i][j],g[i+2][j-1+(a[i+1]=='B')]-(a[i+1]=='Q'));
            }
        }
        for(int i=0;i<=n;++i)
        {
            for(int j=1;j<=a2[n];++j) g[i][j]=min(g[i][j],g[i][j-1]);
        }
        int s=1e9;
        for(int i=1;i<=n;++i)
        {
            for(int j=m;j<=a0[n]+a1[n]+a2[n];++j)
            {
                int w1=a1[i]-(i-(j-m)*2),w2=a2[i]-(j-m);
                if(f[i][w2]>=w1&&g[i+1][w2]<=w1) s=min(s,j);
            }
        }
        if(s==1e9) printf("IMPOSSIBLE\n");
        else printf("%d\n",s+1);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3732kb

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: 5752kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 93ms
memory: 51268kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

184
372
316
161
118
527
IMPOSSIBLE
631
181
269
33
160
642

result:

wrong answer 6th lines differ - expected: '534', found: '527'