QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#691503 | #7743. Grand Finale | VictorYuan | WA | 46ms | 71652kb | C++11 | 2.2kb | 2024-10-31 11:42:26 | 2024-10-31 11:42:27 |
Judging History
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,max(0,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: 0ms
memory: 5820kb
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: 5700kb
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: 71652kb
input:
13 184 887 WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...
output:
184 96 175 161 118 192 110 214 134 117 33 160 171
result:
wrong answer 2nd lines differ - expected: '372', found: '96'