結果
| 問題 |
No.1421 国勢調査 (Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-05 22:40:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,091 bytes |
| コンパイル時間 | 2,364 ms |
| コンパイル使用メモリ | 202,476 KB |
| 最終ジャッジ日時 | 2025-01-19 11:35:37 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#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;
}
}
}
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]);
}
}