結果

問題 No.1421 国勢調査 (Hard)
ユーザー KudeKude
提出日時 2021-03-06 00:29:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,696 bytes
コンパイル時間 4,672 ms
コンパイル使用メモリ 259,580 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 12:29:14
合計ジャッジ時間 6,422 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
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 AC 24 ms
5,376 KB
testcase_23 AC 23 ms
5,376 KB
testcase_24 AC 23 ms
5,376 KB
testcase_25 AC 23 ms
5,376 KB
testcase_26 AC 23 ms
5,376 KB
testcase_27 AC 23 ms
5,376 KB
testcase_28 AC 22 ms
5,376 KB
testcase_29 AC 22 ms
5,376 KB
testcase_30 AC 21 ms
5,376 KB
testcase_31 AC 20 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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