結果
問題 | No.1421 国勢調査 (Hard) |
ユーザー |
![]() |
提出日時 | 2021-01-27 23:24:41 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,403 bytes |
コンパイル時間 | 1,820 ms |
コンパイル使用メモリ | 99,132 KB |
最終ジャッジ日時 | 2025-01-18 08:27:42 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 WA * 15 |
ソースコード
#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::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 |= 1 << 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;}}