QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#122737#2617. Browsing the CollectionzswzswzswWA 2ms5592kbC++171.7kb2023-07-10 23:19:262023-07-10 23:19:28

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:19:28]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5592kb
  • [2023-07-10 23:19:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=510;
int n,m;
int A[N][33],L[N][53],R[N][53];
int fa[N][53],d[N][53];
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;
}
bool chk(int u,int v,int w){
	if(v==w) return 0;
	if(v>w) return u<=v&&u>w;
	return u<=v||u>w;
}
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=L[u][s2];
				if(v!=L[u][s])update(v,s2,w+1);
				v=gF(v,s2);
				while(chk(v,u,L[u][s])){
					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: 2ms
memory: 5592kb

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 3 2 3 1 2 1 
1 0 1 2 2 2 1 3 2 
2 1 0 1 1 2 1 3 2 
3 2 1 0 1 1 1 3 2 
3 2 2 1 0 1 1 3 2 
3 1 2 2 1 0 1 2 2 
2 1 3 3 2 1 0 1 2 
2 1 3 4 2 2 1 0 1 
1 1 3 4 2 3 2 1 0 

result:

wrong answer 4th numbers differ - expected: '1', found: '3'