結果
問題 | No.2895 Zero XOR Subset |
ユーザー | null |
提出日時 | 2024-09-20 22:23:42 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | WA | - |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,944 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 2 ms
6,940 KB |
testcase_36 | WA | - |
ソースコード
#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; }