結果

問題 No.1421 国勢調査 (Hard)
ユーザー publflpublfl
提出日時 2021-03-05 23:05:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 51,200 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-16 11:04:40
合計ジャッジ時間 2,363 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 43 ms
8,064 KB
testcase_23 AC 43 ms
8,192 KB
testcase_24 AC 43 ms
8,192 KB
testcase_25 AC 44 ms
7,936 KB
testcase_26 AC 43 ms
8,192 KB
testcase_27 AC 42 ms
8,064 KB
testcase_28 AC 43 ms
8,064 KB
testcase_29 AC 43 ms
8,064 KB
testcase_30 AC 43 ms
8,064 KB
testcase_31 AC 42 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

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