結果

問題 No.1421 国勢調査 (Hard)
ユーザー KKT89KKT89
提出日時 2021-03-05 22:36:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,385 bytes
コンパイル時間 2,473 ms
コンパイル使用メモリ 206,580 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 10:22:06
合計ジャッジ時間 3,883 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

constexpr ll mod=1e9+7;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	vector<pair<ll,int>> basis;
	for(int i=0;i<m;i++){
		int a; cin >> a;
		ll u=0;
		while(a--){
			int b; cin >> b; b--;
			u+=(1LL<<b);
		}
		int y; cin >> y;
		for(auto e:basis){
			ll uu=(u^e.first);
			if(u>uu){
				u=uu;
				y^=e.second;
			}
		}
		if(u>0){
			basis.push_back({u,y});
		}
		else{
			if(y!=0){
				printf("-1\n"); return 0;
			}
		}
	}
	{
		vector<pair<ll,int>> n_basis;
		for(auto e:basis){
			ll u=e.first;
			int y=e.second;
			for(auto ee:basis){
				if(e==ee)continue;
				ll uu=(u^ee.first);
				if(u>uu){
					u=uu;
					y^=ee.second;
				}
			}
			if(u>0){
				n_basis.push_back({u,y});
			}
		}
		swap(basis,n_basis);
	}
	sort(basis.begin(), basis.end());
	vector<int> res(n,-1);
	for(auto e:basis){
		for(int i=n-1;i>=0;i--){
			if((1LL<<i)&e.first){
				ll u=e.second;
				for(int j=i-1;j>=0;j--){
					if((1LL<<j)&e.first){
						if(res[j]==-1)res[j]=0;
						else{
							u^=res[j];
						}
					}
				}
				res[i]=u; break;
			}
		}
	}
	for(int i=0;i<n;i++){
		if(res[i]==-1)res[i]=0;
		printf("%d\n",res[i]);
	}
}
0