QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691497#7743. Grand FinaleVictorYuanWA 46ms71704kbC++112.2kb2024-10-31 11:40:482024-10-31 11:40:48

Judging History

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

  • [2024-10-31 11:40:48]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:71704kb
  • [2024-10-31 11:40:48]
  • 提交

answer

#include<bits/stdc++.h>
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#define ll long long 
using namespace std;
const int M=5010;
int dp[M][M],f[M][M];
int a[M],g[M]; 
int n,m,x,y,z,ans,T;
string c,s;
void work(int now,int yi,int er,int ci)
{
  for(;ci;now++,ci--)
  {
    if(a[now+1]==1) yi++;
    if(a[now+1]==2) er++;
  }
  dp[now][er]=max(dp[now][er],yi);
}
int main()
{
	//freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); 
  cin>>T;
  while(T--)
  {
    for(int i=0;i<=n+m+5;++i)
      for(int j=0;j<=g[m]+z+5;++j)
        dp[i][j]=f[i][j]=0;
    for(int i=0;i<=n+m+5;++i) a[i]=g[i]=0;
    ans=1e9; x=y=z=0; 
    cin>>n>>m;  cin>>c>>s;
    for(auto o:c) 
    { 
      if(o=='B') z++;
      if(o=='Q') y++;
      if(o=='W') x++;
    }
    for(int i=0;i<m;++i)
    {
      if(s[i]=='B') a[i+1]=2;
      if(s[i]=='Q') a[i+1]=1;
      if(s[i]=='W') a[i+1]=0;
    }
    for(int i=1;i<=m;++i) g[i]=g[i-1]+(a[i]==2);
    for(int i=0;i<=g[m]+z;++i) f[m][i]=f[m-1][i]=0;
    f[m-1][0]=1; 
    f[m][g[m]+z+1]=f[m-1][g[m]+z+1]=1e9;
    for(int i=m-2;i>=0;--i)
    {
      f[i][g[m]+z+1]=1e9;
      for(int j=0;j<=g[m]+z;++j)
      {
        f[i][j]= f[i+1][j+(a[i+1]==2)] + (a[i+1]!=1) ;
        if(a[i+1]==1) f[i][j]=max(f[i][j],1);//!!!!!
        if(j==0) continue;
        f[i][j]=min( f[i][j] , f[i+2][j-(a[i+1]!=2)] - (a[i+1]==1) );
        f[i][j]=max(f[i][j],0);
      }
    }  
    /*for(int i=0;i<=m;++i)
    {
        for(int j=0;j<=g[m]+z;++j)
        {
          cout<<i<<" "<<j<<" "<<f[i][j]<<endl;
        }
    }*/
    for(int i=0;i<=m+1;++i)
      for(int j=0;j<=g[m]+z+2;++j)
        dp[i][j]=-1;
    dp[0][z]=y;
    for(int i=0;i<=m;++i)
    {
      for(int j=0;j<=g[m]+z;++j)
      {
        if(dp[i][j]<0) continue;
        if(dp[i][j]>=f[i][j]) ans=min(ans,(g[i]+z-j)+n);
        if(dp[i][j]>0) work(i,j  ,dp[i][j]-1,1);
        if(      j >0) work(i,j-1,dp[i][j]  ,2);
      }
    }
    //if(m==1) {  if(y+z) ans=n; else ans=1e9; }
    if(ans>1e4) cout<<"IMPOSSIBLE\n";
    else cout<<ans<<"\n";
  }
	return 0;
}

詳細信息

Test #1:

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

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

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 46ms
memory: 71704kb

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:

148
96
175
139
107
192
110
214
134
117
31
160
171

result:

wrong answer 1st lines differ - expected: '184', found: '148'