結果
| 問題 |
No.2895 Zero XOR Subset
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-09-26 09:49:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,260 bytes |
| コンパイル時間 | 631 ms |
| コンパイル使用メモリ | 41,852 KB |
| 最終ジャッジ日時 | 2025-02-24 12:44:20 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 WA * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:33:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | for (int i = 0; i < n; i++) scanf("%lld", as + i);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2895.cc: No.2895 Zero XOR Subset - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int BN = 60;
/* typedef */
using ll = long long;
/* global variables */
ll as[MAX_N], bs[MAX_N];
/* subroutines */
inline int biti(ll a, int i) { return (a >> i) & 1; }
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lld", as + i);
n = min(BN + 1, n);
for (int i = 0; i < n; i++) bs[i] = (1LL << i);
for (int i = 0, u = 0; u < n && i < BN; i++) {
if (! biti(as[u], i)) {
for (int v = u + 1; v < n; v++)
if (biti(as[v], i)) {
swap(as[u], as[v]); swap(bs[u], bs[v]);
break;
}
if (! biti(as[u], i)) continue;
}
for (int v = u + 1; v < n; v++)
if (biti(as[v], i))
as[v] ^= as[u], bs[v] ^= bs[u];
u++;
}
int xi = -1;
for (int i = 0; xi < 0 && i < n; i++)
if (as[i] == 0) xi = i;
if (xi >= 0) {
ll bx = bs[xi];
int m = 0;
for (int i = 0; i < BN; i++)
if (biti(bx, i)) bs[m++] = i;
printf("%d\n", m);
for (int i = 0; i < m; i++)
printf("%lld%c", bs[i] + 1, (i + 1 < m) ? ' ' : '\n');
}
else
puts("-1");
return 0;
}
tnakao0123