結果

問題 No.1421 国勢調査 (Hard)
ユーザー publflpublfl
提出日時 2021-03-05 23:05:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 50,428 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-10-07 04:34:54
合計ジャッジ時間 2,050 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>

int check[110];
int x[10010][110];
int y[10010];

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=b;i++)
	{
		int c;
		scanf("%d",&c);
		for(int j=1;j<=c;j++)
		{
			int d;
			scanf("%d",&d);
			x[i][d] = 1;
		}
		scanf("%d",&y[i]);
	}
	
	for(int i=1;i<=b;i++)
	{
		for(int j=1;j<=a;j++)
		{
			if(x[i][j]==1)
			{
				for(int k=1;k<=b;k++)
				{
					if(k==i) continue;
					if(x[k][j]==1)
					{
						for(int l=1;l<=a;l++) x[k][l] ^= x[i][l];
						y[k] ^= y[i];
					}
				}
				goto u;
			}
		}
		if(y[i]!=0)
		{
			printf("-1");
			return 0;
		}
		u:;
	}
	
	for(int i=1;i<=a;i++) check[i] = -1;
	
	for(int i=b;i>=1;i--)
	{
		std::vector<int> temp;
		for(int j=1;j<=a;j++)
		{
			if(x[i][j]==1)
			{
				if(check[j]==-1) temp.push_back(j);
				else y[i] ^= check[j];
			}
 		}
 		if(!temp.empty())
 		{
 			check[temp[0]] = y[i];
 			for(int j=1;j<temp.size();j++) check[temp[j]] = 0;
		}
	}
	
	for(int i=1;i<=a;i++)
	{
		if(check[i]==-1) printf("0\n");
		else printf("%d\n",check[i]);
	}
}
0