結果
問題 | No.184 たのしい排他的論理和(HARD) |
ユーザー |
![]() |
提出日時 | 2016-01-16 14:18:24 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 52 ms / 5,000 ms |
コード長 | 1,523 bytes |
コンパイル時間 | 1,287 ms |
コンパイル使用メモリ | 161,120 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-04 12:05:54 |
合計ジャッジ時間 | 3,597 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; // uint64_t 吐き出し法 std::vector<uint64_t> sweep_uint64(const std::vector<uint64_t> &A) { auto a = A; int n = a.size(); int row = 0; // O(64*N) for (int col = 63; col >= 0; --col) { int pivot = row; //row 行目以降だけ見る // 先頭から col 番目のビットが立っている a[i] を見つける while ( pivot < n && !(a[pivot] & 1ULL<<col) ) ++pivot; // col 番目にビットが立つ a はなかった if (pivot == n) continue; swap(a[row], a[pivot]); for (int i = row+1; i < n; ++i) { if ( a[i] & 1ULL<<col) a[i] ^= a[row]; } ++row; } return a; } class HappyXorHard { public: void solve(void) { int N; cin>>N; vector<uint64_t> A(N); REP(i,N) cin>>A[i]; A = sweep_uint64(A); int k = count_if(RANGE(A), [](uint64_t a) { return (a>0); }); cout<<(1LL<<k)<<endl; } }; #if 1 int main(int argc, char *argv[]) { ios::sync_with_stdio(false); auto obj = new HappyXorHard(); obj->solve(); delete obj; return 0; } #endif