結果
| 問題 |
No.2895 Zero XOR Subset
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-09-28 17:59:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 1,260 bytes |
| コンパイル時間 | 1,402 ms |
| コンパイル使用メモリ | 173,176 KB |
| 実行使用メモリ | 14,136 KB |
| 最終ジャッジ日時 | 2024-09-28 17:59:35 |
| 合計ジャッジ時間 | 4,587 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 35 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:43:26: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’
43 | for(auto [u, v]: d){
| ^
ソースコード
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pi acos(-1)
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<int, int> PII;
const int N = 1e6 + 10, M = 5010, mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector <int> a(n + 1);
int p = -1;
unordered_map <int, int> mp;
int p2 = -1, p3 = -1;
for(int i = 0; i < n; i++){
cin >> a[i];
if(a[i] == 0){
p = i;
}
if(mp[a[i]] != 0){
p2 = mp[a[i]];
p3 = i;
}
mp[a[i]] = i;
}
if(p != -1){
cout << 1 << "\n";
cout << p + 1 << "\n";
return;
}
if(p2 != -1){
cout << 2 << "\n";
cout << p2 + 1 << " " << p3 + 1 << "\n";
return;
}
vector <PII> d;
for(int i = 0; i < n; i++){
int num = a[i], idx = (1LL << i);
vector <int> ans;
for(auto [u, v]: d){
if((num ^ u) < num){
num = num ^ u;
idx = idx ^ v;
}
}
if(num == 0){
for(int j = 0; j <= 60; j++){
if((idx >> j) & 1) ans.push_back(j + 1);
}
cout << ans.size() << "\n";
for(auto c : ans) cout << c << " ";
cout << "\n";
return;
}
d.push_back({num, idx});
}
cout << -1 << "\n";
}
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T = 1;
//cin >> T;
while(T--) {
solve();
}
}
vjudge1