結果
| 問題 |
No.1421 国勢調査 (Hard)
|
| コンテスト | |
| ユーザー |
57tggx
|
| 提出日時 | 2021-01-28 01:03:42 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,470 bytes |
| コンパイル時間 | 1,931 ms |
| コンパイル使用メモリ | 99,888 KB |
| 最終ジャッジ日時 | 2025-01-18 08:28:39 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#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;
}
}
57tggx