結果
問題 | No.2895 Zero XOR Subset |
ユーザー |
![]() |
提出日時 | 2024-11-13 15:04:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 523 ms / 2,000 ms |
コード長 | 1,821 bytes |
コンパイル時間 | 2,351 ms |
コンパイル使用メモリ | 212,332 KB |
最終ジャッジ日時 | 2025-02-25 04:04:32 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const int BITLEN=60; //bitsetの昇順 bool bitasc(const bitset<BITLEN> &a, const bitset<BITLEN> &b){ for (int i=BITLEN-1; i>=0; i--){ if (a[i] != b[i]){ return a[i] < b[i]; } } return false; } //bitsetのmin bitset<BITLEN> min(bitset<BITLEN> a, bitset<BITLEN> b){ if (bitasc(a, b)) return a; return b; } const ll modc=998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, A; cin >> N; vector<pair<bitset<BITLEN>, int>> vec(N); vector<pair<bitset<BITLEN>, int>> base; for (int i=0; i<N; i++){ cin >> A; vec[i] = {A, i}; } //A_iに作用したindex vector<vector<ll>> v(N); vector<ll> ans, cnt; map<ll, vector<ll>> mp; auto dfs=[&](auto self, int from)->vector<ll>{ if (mp.count(from)) return mp[from]; vector<ll> res(N), res2; res[from]++; for (auto to : v[from]){ assert(to < from); res2 = self(self, to); for (int i=0; i<N; i++) res[i] += res2[i]; } return mp[from] = res; }; for (int i=0; i<N; i++){ for (auto &[e, x] : base){ if (bitasc(vec[i].first^e, vec[i].first)){ vec[i].first = vec[i].first^e; v[i].push_back(x); } } if (vec[i].first.any()) base.push_back(vec[i]); else{ cnt = dfs(dfs, i); for (int j=0; j<N; j++){ if (cnt[j] % 2 == 1) ans.push_back(j+1); } cout << ans.size() << endl; for (auto x : ans) cout << x << " "; cout << endl; return 0; } } cout << -1 << endl; return 0; }