QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#261354 | #7743. Grand Finale | ucup-team1447 | WA | 132ms | 104248kb | C++14 | 2.3kb | 2023-11-22 20:31:28 | 2023-11-22 20:31:29 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 5005
#define inf 0x3f3f3f3f
int n,m,up,T;
char t[maxn],s[maxn];
int a[maxn],s0[maxn];
int f[maxn][maxn],g[maxn][maxn];
void work(int O)
{
n=read(),m=read();
cin>>(t+1);
cin>>(s+1);
For(i,1,m){
if(s[i]=='Q')a[i]=1;
if(s[i]=='B')a[i]=2;
if(s[i]=='W')a[i]=0;
s0[i]=s0[i-1]+(a[i]==0);
}
// memset(f,63,sizeof f);
up=n+m;
For(i,0,up) f[m+1][i]=f[m+2][i]=0;
Rep(i,m,1){
For(j,0,up){
f[i][j]=inf;
// draw 1
if(j) f[i][j]=min(f[i][j],f[i+1][j-1+(a[i]==1)]-(a[i]==2));
// draw 2
if(i+2>=m) f[i][j]=min(f[i][j],1);
else f[i][j]=min(f[i][j],max(0,f[i+2][j+(a[i]==1)]-(a[i]==2))+1);
f[i][j]=max(f[i][j],0);
// cout<<"i,j "<<i<<" "<<j<<" "<<f[i][j]<<"\n";
}
}
int c1=0,c2=0,c0=0,res=inf;
For(i,1,n){
if(t[i]=='Q')++c1;
else if(t[i]=='B')++c2;
else ++c0;
}
For(i,0,m) For(j,0,up) g[i][j]=-inf;
g[0][c1]=c2;
For(i,0,m-1){
For(j,0,up){
if(g[i][j]==-inf)continue;
// use 1
if(j){
int nj=j-1+(a[i+1]==1);
g[i+1][nj]=max(g[i+1][nj],g[i][j]+(a[i+1]==2));
}
if(g[i][j]>0){
if(i+2<=m){
int nj=j+(a[i+1]==1)+(a[i+2]==1);
g[i+2][nj]=max(g[i+2][nj],g[i][j]-1+(a[i+1]==2)+(a[i+2]==2));
}else{
int nj=j+(a[i+1]==1);
g[i+1][nj]=max(g[i+1][nj],g[i][j]-1+(a[i+1]==2));
}
}
}
}
For(i,0,m){
For(j,0,up){
if(g[i][j]>=f[i+1][j]){
res=min(res,c0+s0[i]+j+g[i][j]);
}
}
}
if(res==inf)puts("IMPOSSIBLE");
else cout<<res<<"\n";
}
signed main()
{
// freopen("data.in","r",stdin);
// freopen("my.out","w",stdout);
T=read();
For(_,1,T)work(_);
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5484kb
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: 5520kb
input:
2 3 8 QBG BBBWBWWW 3 8 QBG BBBWBWWW
output:
3 3
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 132ms
memory: 100572kb
input:
13 184 887 WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...
output:
184 372 316 161 118 534 IMPOSSIBLE 631 183 276 33 160 643
result:
ok 13 lines
Test #4:
score: 0
Accepted
time: 73ms
memory: 104248kb
input:
32 887 278 BQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQQWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQBWW...
output:
887 981 15 18 60 9 108 268 475 17 52 12 IMPOSSIBLE IMPOSSIBLE IMPOSSIBLE 76 14 182 907 537 19 19 233 10 38 111 143 103 159 14 IMPOSSIBLE 225
result:
ok 32 lines
Test #5:
score: -100
Wrong Answer
time: 11ms
memory: 58912kb
input:
120 37 178 BQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBG BWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQQWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQ 21 184 QQBQBWQQQBWQWQBWWBQQG QWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBB...
output:
37 24 41 23 46 22 21 24 31 178 23 26 50 IMPOSSIBLE 23 24 25 24 IMPOSSIBLE 43 17 37 35 46 44 42 25 44 33 33 8 14 21 IMPOSSIBLE 36 32 50 79 IMPOSSIBLE 42 34 42 11 IMPOSSIBLE 32 35 44 13 50 IMPOSSIBLE 47 IMPOSSIBLE 37 16 42 38 IMPOSSIBLE 34 37 30 45 IMPOSSIBLE 46 42 42 34 30 32 27 IMPOSSIBLE 25 14 39 3...
result:
wrong answer 43rd lines differ - expected: '12', found: '11'