結果

問題 No.1421 国勢調査 (Hard)
ユーザー KKT89KKT89
提出日時 2021-03-05 22:13:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,139 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 202,372 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 09:47:42
合計ジャッジ時間 5,705 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
			}
		}
	}
	reverse(basis.begin(), basis.end());
	vector<int> res(n,-1);
	for(auto e:basis){
		for(int i=n-1;i>=0;i--){
			if(res[i]!=-1)continue;
			if((1LL<<i)&e.first){
				ll u=e.second;
				for(int j=0;j<n;j++){
					if(j==i)continue;
					if((1<<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]);
	}
}
0