結果
| 問題 | No.2895 Zero XOR Subset |
| コンテスト | |
| ユーザー |
👑 null
|
| 提出日時 | 2024-09-20 22:23:42 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,744 bytes |
| コンパイル時間 | 3,105 ms |
| コンパイル使用メモリ | 250,984 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-20 22:23:51 |
| 合計ジャッジ時間 | 8,699 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 WA * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_BITS = 60;
vector<ll> basis(MAX_BITS, 0); // Linear basis array of size 60
vector<int> basis_idx(MAX_BITS); // To store one index corresponding to each basis vector
// Function to insert number into the basis
bool insertBasis(ll x, int idx) {
vector<int> result;
for (int i = MAX_BITS - 1; i >= 0; --i) {
if (!(x & (1LL << i))) continue; // Skip if bit is not set
if (!basis[i]) { // If this bit is not yet in the basis
basis[i] = x;
basis_idx[i] = idx; // Store the index of this element
return true; // Inserted successfully
}
// Reduce x by the basis element
x ^= basis[i];
result.push_back(basis_idx[i]);
}
// If x becomes 0, it means this element is a combination of basis elements
result.push_back(idx);
// Output the result indices
printf("%d\n", (int)result.size());
for (int i : result) {
printf("%d ", i + 1); // Output 1-based index
}
printf("\n");
return false; // This element was not added to the basis
}
int main() {
int n;
scanf("%d", &n);
vector<ll> a(n);
// Input the array
for (int i = 0; i < n; ++i) {
scanf("%lld", &a[i]);
}
// Insert each element into the basis
for (int i = 0; i < n; ++i) {
if (a[i] == 0) { // Handle edge case where element is already zero
printf("1\n%d\n", i + 1);
return 0;
}
if (!insertBasis(a[i], i)) {
return 0; // Found a subset that XORs to zero, so stop
}
}
// If no zero XOR subset was found, output -1
puts("-1");
return 0;
}
null