結果
| 問題 |
No.1421 国勢調査 (Hard)
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-03-05 22:23:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 165 ms / 2,000 ms |
| コード長 | 1,561 bytes |
| コンパイル時間 | 4,026 ms |
| コンパイル使用メモリ | 256,460 KB |
| 最終ジャッジ日時 | 2025-01-19 11:25:06 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001
int n,m;
vector<int> a,y;
vector<vector<int>> b;
void Gauss(vector<bitset<52>> &B){
int now = 0;
rep(i,52){
int temp = -1;
for(int j=now;j<B.size();j++){
if(B[j][i]){
temp = j;
break;
}
}
if(temp==-1)continue;
rep(j,B.size()){
if(temp==j)continue;
if(B[j][i])B[j] ^= B[temp];
}
swap(B[now],B[temp]);
now++;
}
while(B.size()>0){
rep(j,B.back().size()){
if(B.back()[j]!=0)return;
}
B.pop_back();
}
}
int main(){
cin>>n>>m;
a.resize(m);
b.resize(m);
y.resize(m);
rep(i,m){
cin>>a[i];
b[i].resize(a[i]);
rep(j,a[i]){
cin>>b[i][j];
b[i][j]--;
}
cin>>y[i];
}
vector<int> ans(n,0);
rep(i,30){
vector<bitset<52>> B;
rep(j,m){
int ind = -1;
bitset<52> bb;
rep(k,a[j]){
bb[b[j][k]] = 1;
}
if((y[j]>>i)&1)bb[51] = 1;
B.push_back(bb);
}
Gauss(B);
vector<int> t(n,-1);
rep(j,B.size()){
int temp = B[j][51];;
vector<int> ind;
rep(k,n){
if(B[j][k]){
if(t[k]==-1){
ind.push_back(k);
}
else{
temp ^= t[k];
}
}
}
if(ind.size()==0 && temp){
cout<<-1<<endl;
return 0;
}
rep(k,ind.size()){
if(k==0)t[ind[k]] = temp;
else t[ind[k]]= 0;
}
}
rep(j,n){
if(t[j]==-1)t[j] = 0;
ans[j] |= t[j]<<i;
}
}
rep(i,n)cout<<ans[i]<<endl;
return 0;
}
沙耶花