結果

問題 No.1421 国勢調査 (Hard)
ユーザー 57tggx57tggx
提出日時 2021-01-28 01:03:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,470 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 75,732 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 07:41:26
合計ジャッジ時間 4,637 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cassert>

struct ReduceMap{
	std::vector<std::pair<uint64_t, uint32_t>> vec;
	ReduceMap(std::size_t n): vec(n) {}
	bool insert(uint64_t key, uint32_t value){
		if(key == 0){
			return value == 0;
		}else{
			int index = __builtin_ctzll(key);
			if(vec[index].first == 0){
				vec[index].first = key;
				vec[index].second = value;
				return true;
			}else{
				return insert(key ^ vec[index].first, value ^ vec[index].second);
			}
		}
	}
	std::vector<uint32_t> construct() const {
		std::size_t n = vec.size();
		std::vector<uint32_t> ret(n, 0);
		for(std::size_t i = n - 1;; --i){
			if(vec[i].first){
				uint32_t x = vec[i].second;
				for(std::size_t j = i + 1; j < n; ++j){
					if(vec[i].first >> j & 1){
						x ^= ret[j];
					}
				}
				ret[i] = x;
			}
			if(i == 0){
				return std::move(ret);
			}
		}
	}
};

int main(){
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::size_t n, m;
	std::cin >> n >> m;
	assert(1 <= n && n <= 50);
	assert(1 <= m && m <= 100000);
	ReduceMap map(n);
	for(std::size_t i = 0; i < m; ++i){
		std::size_t a;
		std::cin >> a;
		uint64_t visited = 0;
		for(std::size_t j = 0; j < a; ++j){
			int b;
			std::cin >> b;
			--b;
			visited |= 1ull << b;
		}
		uint32_t y;
		std::cin >> y;
		if(!map.insert(visited, y)){
			std::cout << "-1" << std::endl;
			return 0;
		}
	}
	auto ans = map.construct();
	for(uint32_t i : ans){
		std::cout << i << std::endl;
	}
}
0