結果

問題 No.2895 Zero XOR Subset
ユーザー vjudge1
提出日時 2024-10-07 17:31:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 4,598 bytes
コンパイル時間 4,463 ms
コンパイル使用メモリ 332,656 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-07 17:32:09
合計ジャッジ時間 9,315 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#ifdef ONLINE_JUDGE
#pragma GCC optimize(3, "Ofast", "inline")
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rt return
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pu pair<ull, ull>
#define int long long
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define Endl endl
#define all(x) x.begin(), x.end()
#define all1(x) next(x.begin()), x.end()
#define lll __int128_t
#define ulll __uint128_t
using namespace std;
const int maxn = 1e5 + 50;
const int mod = 998244353;
const ll maxl = 2e18 + 5;
const int maxi = 1e9 + 7;
struct LinearBase
{
// ????? idx?1??
// ????? idx?0??
int N;
vector<ull> base;
vector<int> idx;
int iffzero = 0;
LinearBase()
{
N = 105;
base.resize(102);
}
LinearBase(int n)
{
N = n + 5;
base.resize(n + 20);
idx.resize(n + 20);
}
void clear()
{
N = 0;
base.clear();
}
bool insert(ull x, int dx)
{
assert(N != 0);
for (int i = 62; i >= 0; i--)
{
if (!(x & (1ull << i)))
continue;
if (!base[i])
{
base[i] = x;
idx[i] = dx;
return 1;
}
x ^= base[i];
if (x == 0)
{
iffzero = 1;
return false;
}
}
return 1;
}
void goass()
{
assert(N != 0);
sort(base.begin(), base.end(), greater<ull>());
int row = 0;
for (int i = 62; i >= 0; i--)
{
for (int j = row; j < N; j++)
{
if ((1ull << i) & base[j])
{
swap(base[j], base[row]);
swap(idx[j],idx[row]);
}
}
if (!((1ull << i) & base[row]))
continue;
for (int j = 0; j < N; j++)
{
if (j == row)
continue;
if ((1ull << i) & base[j])
{
base[j] ^= base[row];
}
}
row++;
}
}
void printbi(ull x)
{
for (int j = 62; j >= 0; j--)
{
if ((1ull << j) & x)
{
cerr << 1;
}
else
cerr << 0;
}
cerr << endl;
}
void print()
{
assert(N != 0);
for (int i = 0; i < N; i++)
{
for (int j = 62; j >= 0; j--)
{
if ((1ull << j) & base[i])
{
cerr << 1;
}
else
cerr << 0;
}
cerr << endl;
}
cerr << endl;
}
};
void init()
{
}
void solve()
{
int n;
cin >> n;
vector<ull> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
LinearBase lb(105);
vector<int> ans;
vector<int> ans2;
for (int i = 1; i <= n; i++)
{
if(a[i]==0) ans2.push_back(i);
else
if (!lb.insert(a[i], i))
{
// lb.goass();
ull x = a[i];
for (int j = 62; j >= 0; j--)
{
if (!(x & (1ull << j)))
continue;
x ^= a[lb.idx[j]];
if(lb.idx[j]!=0)
ans.push_back(lb.idx[j]);
}
for (int j = 62; j >= 0; j--)
{
if (!(x & (1ull << j)))
continue;
x ^= lb.base[j];
if(lb.idx[j]!=0)
ans.push_back(lb.idx[j]);
}
ans.push_back(i);
break;
}
}
ranges::sort(ans);
if(ans2.size()>=1)
{
cout<<ans2.size()<<endl;
for(int i=0;i<ans2.size();i++)
{
cout<<ans2[i]<<" \n"[i==ans2.size()-1];
}
}
else
if(ans.size())
{
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++)
{
cout<<ans[i]<<" \n"[i==ans.size()-1];
}
}
else
{
cout<<-1<<endl;
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt", "r", stdin);
freopen("2.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int __ = 1;
// std::cin >> __;
init();
while (__--)
{
solve();
// cerr<<"TIME"<<qq-__<<endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0