QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#394451#7743. Grand Finale2745518585WA 0ms3724kbC++202.3kb2024-04-20 14:52:072024-04-20 14:52:08

Judging History

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

  • [2024-04-20 14:52:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3724kb
  • [2024-04-20 14:52:07]
  • 提交

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+1]=='B')]-(a[i+1]=='Q')+1);
                if(j>0) g[i][j]=min(g[i][j],g[i+2][j-1+(a[i+2]=='B')]-(a[i+2]=='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: 3696kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3724kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

4
4

result:

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