QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#592994#7736. Red Black Treedaduoli#RE 0ms0kbC++141.6kb2024-09-27 10:59:542024-09-27 10:59:54

Judging History

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

  • [2024-09-27 10:59:54]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-27 10:59:54]
  • 提交

answer

#include<bits/stdc++.h>
#define Yzl unsigned long long
#define mp make_pair
#define pi pair<LL,LL>
#define fi first
#define se second
#define pb emplace_back
typedef long long LL;

using namespace std;

const Yzl Lty=20120712;

const int MAXN=3e3+10;
int n,m,V,s1,s2,s3;
pi f[MAXN][MAXN];
char s[MAXN],ch[MAXN];
bool chk(int x) {
	for(int i=0;i<=m;++i) for(int j=0;j<=V;++j) f[i][j].fi=-Lty;
	if(2*s2+s1>=m) return true;
	f[0][s2]=mp(s1,-s3);
	for(int i=0;i<=m;++i) {
		for(int j=0;j<=V;++j) {
			if(f[i][j].fi<0) continue;
//			if(x==2) {
//				cout<<i<<" "<<j<<" "<<f[i][j].fi<<endl;
//			}
			if(2*j+f[i][j].fi>=m-i) return true;
			if(j&&i+2<=m) {
				int t1=0,t2=0,t3=0;
				if(ch[i+1]=='Q') ++t1;
				if(ch[i+1]=='B') ++t2;
				if(ch[i+1]=='W') ++t3;
				if(-f[i][j].se+j+f[i][j].fi+1<=x) {
					if(ch[i+2]=='Q') ++t1;
					if(ch[i+2]=='B') ++t2;
					if(ch[i+2]=='W') ++t3;
				}
				f[i+2][j+t2-1]=max(f[i+2][j+t2-1],mp(f[i][j].fi+t1,f[i][j].se-t3));
			}
			if(f[i][j].fi) {
				int t1=0,t2=0,t3=0;
				if(ch[i+1]=='Q') ++t1;
				if(ch[i+1]=='B') ++t2;
				if(ch[i+1]=='W') ++t3;
				f[i+1][j+t2]=max(f[i+1][j+t2],mp(f[i][j].fi+t1-1,f[i][j].se-t3));
			}
		}
	} return false;
}
void vmain() {
	scanf("%d%d%s%s",&n,&m,s+1,ch+1); V=m/2;
	s1=0,s2=0,s3=0;
	for(int i=1;i<=n;++i) {
		if(s[i]=='Q') ++s1;
		if(s[i]=='B') ++s2;
		if(s[i]=='W'||s[i]=='G') ++s3;
	}
	int l=n-1,r=n+m+1,mid;
	while(l+1<r) { mid=(l+r)/2;
		if(chk(mid)) r=mid;
		else l=mid;
	} if(r!=n+m+1) printf("%d\n",r); else puts("IMPOSSIBLE");
}
int main () { 
	int T=1; scanf("%d",&T); while(T--) vmain();
	return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

2
9
101011110
1 1 3 3 3 6 2 2
4
1011
1 1 3

output:


result: