結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー koprickykopricky
提出日時 2018-12-10 01:56:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 3,426 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 166,404 KB
実行使用メモリ 5,044 KB
最終ジャッジ日時 2023-09-17 17:47:08
合計ジャッジ時間 4,169 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 38 ms
4,468 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 29 ms
4,376 KB
testcase_11 AC 21 ms
4,376 KB
testcase_12 AC 44 ms
4,720 KB
testcase_13 AC 46 ms
4,804 KB
testcase_14 AC 26 ms
4,376 KB
testcase_15 AC 49 ms
4,808 KB
testcase_16 AC 42 ms
4,612 KB
testcase_17 AC 45 ms
4,660 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 9 ms
4,920 KB
testcase_21 AC 51 ms
5,044 KB
testcase_22 AC 51 ms
4,972 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 30 ms
4,376 KB
testcase_29 AC 43 ms
4,704 KB
testcase_30 AC 39 ms
4,496 KB
testcase_31 AC 32 ms
4,464 KB
testcase_32 AC 40 ms
4,620 KB
testcase_33 AC 50 ms
4,868 KB
testcase_34 AC 49 ms
4,800 KB
testcase_35 AC 51 ms
5,036 KB
testcase_36 AC 51 ms
4,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

template <int COL_SIZE> class mat {
private:
    // (or, and) の意味での積(正方かつ対称行列に限る(重みなし無向グラフの隣接行列とか))
    mat operator*(const mat& m) const {
        mat ans;
        for(int i = 0; i < COL_SIZE; i++){
            for(int j = 0; j < COL_SIZE; j++){
                if(this->a[i][j] == 0) continue;
                ans.a[i] |= m.a[j];
            }
        }
        return ans;
    }
    
public:
    bitset<COL_SIZE>* a;
    int r;
    // 正方行列の場合
    mat(){ a = new bitset<COL_SIZE>[COL_SIZE]; }
    // 一般の行列の場合
    mat(int row_size) : r(row_size){ a = new bitset<COL_SIZE>[r]; }
    inline int rank() const {
        int res = 0;
        mat<COL_SIZE> b(r);
        for(int i = 0; i < r; i++) b[i] = a[i];
        for(int i = 0; i < COL_SIZE; i++){
            if(res == r) return res;
            int pivot = res;
            if(!b[pivot][i]){
                for(int j = res + 1; j < r; j++){
                    if(b[j][i]){
                        pivot = j;
                        break;
                    }
                }
                if(!b[pivot][i]) continue;
                swap(b[pivot], b[res]);
            }
            for(int j = res + 1; j < r; j++){
                if(b[j][i]) b[j] ^= b[res];
            }
            res++;
        }
        return res;
    }
    inline const bitset<COL_SIZE>& operator[](size_t index) const {
        return a[index];
    }
    inline bitset<COL_SIZE>& operator[](size_t index){
        return a[index];
    }
    friend mat pow(mat m, long long cnt){
        mat res;
        for(int i = 0; i < COL_SIZE; i++) res.set(i, i);
        while(cnt){
            if(cnt & 1){
                res = res * m;
            }
            m = m * m;
            cnt >>= 1;
        }
        return res;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    mat<61> m(n);
    rep(i,n){
        ll a;
        cin >> a;
        m[i] = a;
    }
    cout << (1LL << m.rank()) << "\n";
    return 0;
}
0