結果

問題 No.803 Very Limited Xor Subset
ユーザー Kiona0405Kiona0405
提出日時 2020-06-12 01:03:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,671 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 170,452 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-06 08:50:47
合計ジャッジ時間 4,130 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 8 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 3 ms
4,380 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 WA -
testcase_41 AC 5 ms
4,376 KB
testcase_42 WA -
testcase_43 AC 4 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const int MAXBIT = 400;

int main()
{
    int N, M, X;
    cin >> N >> M >> X;

    // convert X as vector format
    vector<int> target(MAXBIT);
    rep(bit, 0, 30)
        if (((1<<bit)&X)>0)
            target[bit] = 1;

    vector<vector<int>> values(N, vector<int>(MAXBIT, 0));
    rep(i, 0, N)
    {
        int A;
        cin >> A;
        
        int bit = 0;
        rep(bit, 0, 30)
            if (((1<<bit)&A) > 0)
                values[i][bit] = 1;
    }
    
    // restriction
    rep(i, 0, M)
    {
        int t, l, r;
        cin >> t >> l >> r;
        --l, --r;

        target[30+i] = t;
        rep(pos, l, r+1) values[pos][30+i] = 1;
    }

    // sweep method
    int rank = 0;
    vector<int> msb(MAXBIT, -1);
    rep(bit, 0, MAXBIT)
    {
        bool exists = false;
        rep(i, rank, N)
        {
            if (values[i][bit] == 1)
            {
                exists = true;
                // swap
                if (i != rank)
                {
                    rep(j, 0, MAXBIT)
                        swap(values[rank][j], values[i][j]);
                }
                break;
            }
        }

        if (!exists) continue;

        // sweep
        // cout << bit << ' ' << rank << endl;
        // pvec(values[rank]);
        rep(i, 0, N)
        {
            if (i==rank) continue;
            if (values[i][bit] == 0) continue;
            rep(j, 0, MAXBIT)
                values[i][j] ^= values[rank][j];
        }

        msb[rank] = bit;
        ++rank;
    }

    // cout << rank << endl;

    //  check ans
    vector<int> status(MAXBIT, 0);
    rank = 0;
    rep(bit, 0, MAXBIT)
    {
        if (target[bit] == 0) continue;
        while (msb[rank]<bit and msb[rank] != -1) ++rank;

        if (msb[rank] == -1 or msb[rank]>bit) break;

        rep(i,0, MAXBIT)
            status[i] ^= values[rank][i];
        ++rank;
    }

    bool is_ok = true;
    rep(bit,0,MAXBIT)
        if (status[bit]!=target[bit]) is_ok = false;

    if (!is_ok)
    {
        cout << 0 << endl;
        return 0;
    }

    ll cnt = 1;
    rep(i, 0, N)
    {
        bool is_zero = true;
        rep(j,0,MAXBIT)
            if (values[i][j] == 1) is_zero = false;
        
        if (is_zero) cnt = (cnt*2)%MOD;
    }
    cout << cnt << endl;
    return 0;
}
0