QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#23055#2549. King's PalaceFudanU1#WA 3ms5816kbC++202.7kb2022-03-11 18:11:522022-04-30 02:16:39

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 02:16:39]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5816kb
  • [2022-03-11 18:11:52]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
char cu[10],cv[10];
int ni[1<<22|7],kk[30],kr[(1<<22)|7],qq[30],tq[30];
ll f[1<<22|7];
bool b[80][80];
int n,m,zt;
int main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++){int u,v,uu,vv;
		scanf("%d%s%d%s",&u,cu,&v,cv);
		uu=u*3;vv=v*3;
		if(cu[0]=='G')uu++;if(cu[0]=='B')uu+=2;
		if(cv[0]=='G')vv++;if(cv[0]=='B')vv+=2;
		b[uu][vv]=1;b[vv][uu]=1;
	}
	//f G or B
	for(int i=1;i<=n;i++)ni[1<<(i-1)]=i;
	f[0]=1;zt=1<<n;
	for(int i=1;i<zt;i++){
		int w=i&-i;int lt=0;
		int iw=i^w;
		for(int j=1;j<=n;j++)if((iw>>(j-1))&1)kk[j]=3,tq[++lt]=j;else kk[j]=0;
		kk[ni[w]]=1;int lq=0;qq[lq=1]=ni[w];
		int ig=iw;//cout<<'['<<lt<<endl;
		while(lq){
			int u=qq[lq];lq--;
			int uu=u*3+kk[u];
			for(int j=1;j<=lt;j++){
				int kks=kk[tq[j]];
				if(b[uu][tq[j]*3+1])kks&=2;
				if(b[uu][tq[j]*3+2])kks&=1;
				//cout<<'>'<<u<<' '<<uu<<' '<<tq[j]<<' '<<kks<<endl;
				if(kks==0){lq=0;ig=zt;break;}
				if(kks<kk[tq[j]]){
					kk[tq[j]]=kks;
					qq[++lq]=tq[j];
					ig^=1<<(tq[j]-1);
				}
			}
		}
		for(int j=1;j<=lt;j++)kk[tq[j]]=3;
		kk[ni[w]]=2;lq=0;qq[lq=1]=ni[w];
		int ib=iw;
		while(lq){
			int u=qq[lq];lq--;
			int uu=u*3+kk[u];
			for(int j=1;j<=lt;j++){
				int kks=kk[tq[j]];
				if(b[uu][tq[j]*3+1])kks&=2;
				if(b[uu][tq[j]*3+2])kks&=1;
				if(kks==0){lq=0;ib=zt;break;}
				if(kks<kk[tq[j]]){
					kk[tq[j]]=kks;
					qq[++lq]=tq[j];
					ib^=1<<(tq[j]-1);
				}
			}
		}
		f[i]=f[ig]+f[ib];
		//cout<<i<<' '<<f[i]<<' '<<ig<<' '<<ib<<endl;
	}
	kr[0]=zt-1;//can be red
	ll zz=f[zt-1];//cout<<zt<<endl;
	for(int i=1;i<zt;i++){//i R
		int w=i&-i;//cout<<kr[0]<<endl;
		int iw=i^w;//cout<<i<<' '<<iw<<' '<<kr[iw]<<endl;
		if(kr[iw]&w){//w can be red
			kr[i]=kr[iw];
			for(int j=1;j<=n;j++)if((i>>(j-1))&1)kk[j]=4;else kk[j]=3;
			int uu=ni[w]*3;int lq=0;int bg=(zt-1)^i;
			for(int j=1;j<=n;j++){
				int kks=kk[j];
				if(b[uu][j*3])kks&=3,kr[i]&=(zt-1)^(1<<(j-1));
				if(b[uu][j*3+1])kks&=6;
				if(b[uu][j*3+2])kks&=5;
				if(kks==0){
					kr[i]=0;bg=zt;break;
				}
				if(kks<kk[j]){
					kk[j]=kks;
					qq[++lq]=j;
					bg^=(1<<(j-1));
				}
			}
			while(lq&&bg<zt){
				int u=qq[lq];lq--;
				int uu=u*3+kk[u];
				for(int j=1;j<=n;j++){
					int kks=kk[j];
					if(b[uu][j*3])kks&=3;
					if(b[uu][j*3+1])kks&=6;
					if(b[uu][j*3+2])kks&=5;
					if(kks==0){bg=zt;break;}
					if(kks<kk[j]){
						kk[j]=kks;
						qq[++lq]=j;
						bg^=1<<(j-1);
					}
				}
			}
			zz+=f[bg];
			//cout<<i<<' '<<zz<<' '<<bg<<' '<<kr[i]<<endl;
		}else kr[i]=0;
	}
	printf("%lld\n",zz);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 5816kb

input:

2 3
1 R 2 R
1 G 2 R
1 B 2 G

output:

1

result:

wrong answer expected '6', found '1'