QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#20563#2617. Browsing the CollectionBinDir0#WA 2ms4240kbC++202.2kb2022-02-16 16:31:522022-05-03 10:35:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-03 10:35:49]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4240kb
  • [2022-02-16 16:31:52]
  • 提交

answer

#include <bits/stdc++.h> 
#define pr pair< int , int > 
#define F first
#define S second
using namespace std;
int n , m , M , a[550][5] , dis[550][1 << 5] , vis[550][1 << 5] , nex[550] , pre[550] , ans[550][550];
vector< pr > son[550][1 << 5];
queue< pr > q;
int main()
{
//	freopen("1.in" , "r" , stdin);
//	freopen("1.out" , "w" , stdout);
	scanf("%d%d" , &n , &m); M = (1 << m) - 1;
	for(int i = 1 ; i <= n ; i++ )
		for(int j = 0 ; j < m ; j++ ) scanf("%d" , &a[i][j]);
	for(int i = 1 ; i <= n ; i++ ) pre[i] = i - 1 , nex[i] = i + 1;
	pre[1] = n; nex[n] = 1;
	for(int i = 1 ; i <= n ; i++ )
	{
		for(int msk = 0 ; msk <= M ; msk++ )
		{
			//right
			int qwq = pre[i]; 
			while(1)
			{
				int f = 1;
				for(int j = 0 ; j < m ; j++ )
					if(a[qwq][j] != a[i][j] && (msk & (1 << j))) { f = 0; break; }
				if(f) 
				{
					if(qwq != i) son[i][msk].push_back({qwq , msk});
					break;
				}
				qwq = pre[qwq];
			}
			//left
			qwq = nex[i]; 
			while(1)
			{
				int f = 1;
				for(int j = 0 ; j < m ; j++ )
					if(a[qwq][j] != a[i][j] && (msk & (1 << j))) { f = 0; break; }
				if(f) 
				{
					if(qwq != i) son[i][msk].push_back({qwq , msk});
					break;
				}
				qwq = nex[qwq];
			}
			//remove
			for(int j = 0 ; j < m ; j++ )
				if(!(msk & (1 << j))) son[i][msk].push_back({i , msk | (1 << j)});
			//add
			qwq = pre[i]; 
			while(1)
			{
				int t = 0 , id = 0;
				for(int j = 0 ; j < m ; j++ )
					if((msk & (1 << j)) && a[qwq][j] != a[i][j]) t++ , id = 1 << j;
				if(!t) break;
				if(t == 1) son[i][msk].push_back({qwq , msk ^ id});
				qwq = pre[qwq]; 
			}
		}
	}
	for(int s = 1 ; s <= n ; s++ ) 
	{
		memset(vis , 0 , sizeof(vis)); 
		for(int msk = 0 ; msk <= M ; msk++ )
			vis[s][msk] = 1 , dis[s][msk] = 0 , q.push({s , msk});
		while(!q.empty())
		{
			int x = q.front().F , y = q.front().S; q.pop();
			for(pr v : son[x][y])
			{
				if(!vis[v.F][v.S]) 
				{
					vis[v.F][v.S] = 1; dis[v.F][v.S] = dis[x][y] + 1;
					q.push(v);
				}
			}
		}
		for(int i = 1 ; i <= n ; i++ ) ans[i][s] = dis[i][0];
	}
	for(int i = 1 ; i <= n ; i++ )
	{
		for(int j = 1 ; j <= n ; j++ ) printf("%d " , ans[i][j]);
		printf("\n");
	}
    return 0;
} 
/*

*/ 

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 4240kb

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

result:

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