結果

問題 No.1421 国勢調査 (Hard)
ユーザー 沙耶花沙耶花
提出日時 2021-03-05 22:23:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 1,561 bytes
コンパイル時間 4,666 ms
コンパイル使用メモリ 258,688 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 10:09:05
合計ジャッジ時間 7,126 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 159 ms
6,940 KB
testcase_23 AC 161 ms
6,944 KB
testcase_24 AC 162 ms
6,940 KB
testcase_25 AC 160 ms
6,944 KB
testcase_26 AC 161 ms
6,944 KB
testcase_27 AC 58 ms
6,944 KB
testcase_28 AC 67 ms
6,944 KB
testcase_29 AC 61 ms
6,944 KB
testcase_30 AC 57 ms
6,944 KB
testcase_31 AC 61 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001
int n,m;
vector<int> a,y;
vector<vector<int>> b;

void Gauss(vector<bitset<52>> &B){
	int now = 0;
	rep(i,52){
		int temp = -1;
		for(int j=now;j<B.size();j++){
			if(B[j][i]){
				temp = j;
				break;
			}
		}
		if(temp==-1)continue;
		
		rep(j,B.size()){
			if(temp==j)continue;
			if(B[j][i])B[j] ^= B[temp];
		}
		
		swap(B[now],B[temp]);
		now++;
	}
	while(B.size()>0){
		rep(j,B.back().size()){
			if(B.back()[j]!=0)return;
		}
		B.pop_back();
	}
}

int main(){
	
	cin>>n>>m;
	
	a.resize(m);
	b.resize(m);
	y.resize(m);
	rep(i,m){
		cin>>a[i];
		b[i].resize(a[i]);
		rep(j,a[i]){
			cin>>b[i][j];
			b[i][j]--;
		}
		cin>>y[i];
	}
	vector<int> ans(n,0);
	rep(i,30){
		
		vector<bitset<52>> B;
		rep(j,m){
			int ind = -1;
			bitset<52> bb;
			rep(k,a[j]){
				bb[b[j][k]] = 1;
			}
			if((y[j]>>i)&1)bb[51] = 1;
			B.push_back(bb);
			
			
		}
		Gauss(B);
		vector<int> t(n,-1);
		rep(j,B.size()){
			int temp = B[j][51];;
			vector<int> ind;
			rep(k,n){
				if(B[j][k]){
					if(t[k]==-1){
						ind.push_back(k);
					}
					else{
						temp ^= t[k];
					}
				}
			}
			if(ind.size()==0 && temp){
				cout<<-1<<endl;
				return 0;
			}
			rep(k,ind.size()){
				if(k==0)t[ind[k]] = temp;
				else t[ind[k]]=  0;
			}
		}
		rep(j,n){
			if(t[j]==-1)t[j] = 0;
			ans[j] |= t[j]<<i;
		}
	}
	
	rep(i,n)cout<<ans[i]<<endl;
	
    return 0;
}
0