結果

問題 No.2895 Zero XOR Subset
ユーザー shinchanshinchan
提出日時 2024-09-20 21:37:27
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,234 bytes
コンパイル時間 2,442 ms
コンパイル使用メモリ 207,468 KB
実行使用メモリ 6,640 KB
最終ジャッジ日時 2024-09-20 21:37:33
合計ジャッジ時間 5,709 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

void chmin(ll &a, ll b) { a = min(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    using B = bitset<200000>;
    vector<ll> basis;
    vector<B> bb;
    rep(i, n) {
        B bit(0);
        bit[i] = 1;
        int sz = basis.size();
        rep(j, sz) {
            if(a[i] > (a[i] ^ basis[j])) {
                a[i] ^= basis[j];
                bit ^= bb[j];
            }
            if(a[i] > basis[j]) {
                swap(bit, bb[j]);
                swap(a[i], basis[j]);
            }
        }
        if(a[i] == 0) {
            cout << bit.count() << endl;
            rep(j, n) if(bit[j]) cout << j + 1 << " ";
            cout << endl;
            return 0;
        } else {
            bb.push_back(bit);
            basis.pb(a[i]);
        }
    }
    cout << -1 << endl;
    return 0;
}
0