QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#263265 | #7743. Grand Finale | ucup-team1134 | WA | 1ms | 5572kb | C++23 | 3.5kb | 2023-11-24 18:00:51 | 2023-11-24 18:00:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=2505,INF=1<<30;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
bool mada[MAX][MAX+MAX];
int dp[MAX][MAX+MAX];
int sumA[MAX],sumB[MAX],sumC[MAX];
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int Q;cin>>Q;
while(Q--){
int N,M;cin>>N>>M;
string S,T;cin>>S>>T;
T+='.';
sumA[0]=sumB[0]=sumC[0]=0;
for(char c:S){
if(c=='Q') sumA[0]++;
if(c=='B') sumB[0]++;
if(c=='W') sumC[0]++;
}
for(int i=1;i<=M;i++){
sumA[i]=sumA[i-1];
sumB[i]=sumB[i-1];
sumC[i]=sumC[i-1];
char c=T[i-1];
if(c=='Q') sumA[i]++;
if(c=='B') sumB[i]++;
if(c=='W') sumC[i]++;
}
int left=N-1,right=N+M+1;
while(right-left>1){
int mid=(left+right)/2;
for(int i=0;i<=M;i++){
for(int j=0;j<=N+M;j++){
mada[i][j]=false;
dp[i][j]=INF;
}
}
if(mid==N){
dp[0][sumA[0]]=sumC[0];
}else{
mada[0][0]=true;
}
for(int i=0;i<M;i++){
bool aaa=false;
for(int a=0;a<=sumA[i];a++){
if(mada[i][a]){
aaa=true;
int b=(i-a)/2;
int A=sumA[i]-a,B=sumB[i]-b,C=sumC[i];
if(A){
mada[i+1][a+1]=true;
}
if(B){
if(1+A+B+C+1==mid){
chmin(dp[min(i+2,M)][A+(T[i]=='Q')+(T[i+1]=='Q')],C+(T[i]=='W')+(T[i+1]=='W'));
}else{
mada[min(i+2,M)][a]=true;
}
}
}
}
for(int a=0;a<=sumA[i];a++){
if(dp[i][a]!=INF){
aaa=true;
int c=dp[i][a],b=mid-1-a-c;
if(a){
chmin(dp[i+1][a-1+(T[i]=='Q')],c+(T[i]=='W'));
}
if(b){
chmin(dp[min(i+2,M)][a+(T[i]=='Q')],c+(T[i]=='W'));
}
}
}
if(!aaa) break;
}
bool ok=false;
for(int a=0;a<=sumA[M];a++){
if(mada[M][a]) ok=true;
if(dp[M][a]!=INF) ok=true;
}
if(ok) right=mid;
else left=mid;
}
if(right<=N+M) cout<<right<<"\n";
else cout<<"IMPOSSIBLE"<<"\n";
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5572kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
IMPOSSIBLE IMPOSSIBLE
result:
wrong answer 1st lines differ - expected: '3', found: 'IMPOSSIBLE'