QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#122728#2617. Browsing the CollectionzswzswzswWA 1ms5336kbC++141.6kb2023-07-10 23:00:392023-07-10 23:00:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-10 23:00:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5336kb
  • [2023-07-10 23:00:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=510;
int n,m;
int A[N][6],L[N][33],R[N][33];
int fa[N][33],d[N][33];
int res[N][N];
struct node{
	int u,s;
};
int hd,tl;
node que[N*N];
int pre(int x){
	--x;if(!x)x=n;return x;
}
int gF(int x,int s){return x==fa[x][s]?x:fa[x][s]=gF(fa[x][s],s);}
void update(int u,int s,int x){
	if(d[u][s]<=x)return;
	d[u][s]=x;que[++tl]=(node){u,s};
	return;
}
void Solve(int x)
{
	hd=1;tl=0;
	for(int i=1;i<=n;i++)
		for(int j=0;j<(1<<m);j++)fa[i][j]=i,d[i][j]=n+1;
	for(int i=0;i<(1<<m);i++){
		d[x][i]=0;
		que[++tl]=(node){x,i};
	}
	while(hd<=tl)
	{
		node tmp=que[hd++];
		int u=tmp.u,s=tmp.s;
		int w=d[u][s];
		update(L[u][s],s,w+1);
		update(R[u][s],s,w+1);
		for(int i=0;i<m;i++)
			if(!(s&(1<<i)))update(u,s^(1<<i),w+1);
			else{
				int s2=s^(1<<i),v=gF(L[u][s2],s2);
				update(v,s2,w+1);
				while(gF(v,s2)!=gF(L[u][s],s2)){
					update(v,s2,w+1);
					//if(gF(L[v][s2],s2)==gF(v,s2))break;
					fa[v][s2]=gF(L[v][s2],s2);
					v=fa[v][s2];
				}update(u,s2,w+1);
					
			}
	}
	for(int i=1;i<=n;i++)if(i!=x)res[i][x]=d[i][0];
	return;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=0;j<m;j++)cin>>A[i][j];
	for(int s=0;s<(1<<m);s++){
		for(int i=1;i<=n;i++)
		{
			for(int j=pre(i);j!=i;j=pre(j)){
				bool tg=1;
				for(int k=0;k<m;k++)
					if(((1<<k)&s)&&A[i][k]!=A[j][k]){tg=0;break;}
				if(tg){L[i][s]=j,R[j][s]=i;break;}
			}
			if(!L[i][s])L[i][s]=R[i][s]=i;
		}
	}
	for(int i=1;i<=n;i++)Solve(i);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)cout<<res[i][j]<<' ';
		puts("");
	}return 0;
		
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5336kb

input:

9 3
5 3 7
5 3 4
5 3 7
5 3 2
5 3 4
5 3 7
2 3 7
5 3 7
2 3 7

output:

0 1 2 1 2 3 1 2 1 
1 0 1 1 2 2 1 3 2 
2 1 0 1 1 2 1 2 2 
3 2 1 0 1 1 1 2 2 
3 2 2 1 0 1 1 2 2 
2 1 2 1 1 0 1 1 2 
2 1 3 1 2 1 0 1 1 
1 1 3 1 2 2 1 0 1 
1 1 2 1 2 3 1 1 0 

result:

wrong answer 26th numbers differ - expected: '3', found: '2'