結果

問題 No.1421 国勢調査 (Hard)
ユーザー Kude
提出日時 2021-03-06 00:29:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,696 bytes
コンパイル時間 4,484 ms
コンパイル使用メモリ 257,412 KB
最終ジャッジ日時 2025-01-19 12:09:52
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<ll, int>> d(m);
    rep(i, m) {
        int t;
        cin >> t;
        ll x = 0;
        rep(_, t) {
            int b;
            cin >> b;
            b--;
            x |= 1LL << b;
        }
        d[i].first = x;
        cin >> d[i].second;
    }
    vector<pair<ll, int>> basis;
    for(auto& [a, y]: d) {
        for(auto [c, z]: basis) {
            if ((a ^ c) < a) {
                a ^= c;
                y ^= z;
            }
        }
        if (a == 0) {
            if (y != 0) {
                cout << -1 << endl;
                return 0;
            }
        } else {
            basis.emplace_back(a, y);
        }
    }
    sort(all(basis));
    VI ans(n);
    for(auto [a, y]: basis) {
        int now = 0;
        rep(i, n) {
            if (a >> i & 1) {
                if (a == (1LL << i)) {
                    ans[i] = now ^ y;
                    break;
                }
                now ^= ans[i];
                a ^= (1LL << i);
            }
        }
    }
    rep(i, n) cout << ans[i] << '\n';
}
0