結果

問題 No.1421 国勢調査 (Hard)
ユーザー merom686merom686
提出日時 2021-03-05 23:39:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,619 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 97,280 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 11:46:25
合計ジャッジ時間 2,536 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 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 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 22 ms
5,376 KB
testcase_23 AC 22 ms
5,376 KB
testcase_24 AC 22 ms
5,376 KB
testcase_25 AC 22 ms
5,376 KB
testcase_26 AC 21 ms
5,376 KB
testcase_27 AC 22 ms
5,376 KB
testcase_28 AC 23 ms
5,376 KB
testcase_29 AC 22 ms
5,376 KB
testcase_30 AC 22 ms
5,376 KB
testcase_31 AC 22 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    P &operator^=(const P &p) {
        b ^= p.b;
        y ^= p.y;
        return *this;
    }
    ll b;
    int y;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<P> p(m);
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;

        ll b = 0;
        for (int j = 0; j < a; j++) {
            int k;
            cin >> k;
            k--;

            b ^= 1LL << k;
        }

        int y;
        cin >> y;

        p[i] = { b, y };
    }

    for (int k = 0; k < n; k++) {
        ll t = 1LL << k;
        int f = 0;
        for (int i = k; i < m; i++) {
            if (p[i].b & t) {
                for (int i1 = i + 1; i1 < m; i1++) {
                    if (p[i1].b & t) p[i1] ^= p[i];
                }
                swap(p[i], p[k]);
                f = 1;
                break;
            }
        }
        if (f == 0) {
            p.push_back({ t, 0 });
            m++;
            swap(p.back(), p[k]);
        }
    }

    for (int i = 0; i < m; i++) {
        if (p[i].b == 0 && p[i].y != 0) {
            cout << -1 << endl;
            exit(0);
        }
    }

    for (int i = n; --i >= 0;) {
        for (int i1 = 0; i1 < i; i1++) {
            if (p[i].b & p[i1].b) {
                p[i1] ^= p[i];
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        cout << p[i].y << '\n';
    }

    return 0;
}
0