結果
| 問題 |
No.803 Very Limited Xor Subset
|
| コンテスト | |
| ユーザー |
Kiona0405
|
| 提出日時 | 2020-06-12 01:03:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,671 bytes |
| コンパイル時間 | 1,927 ms |
| コンパイル使用メモリ | 174,244 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-24 03:34:06 |
| 合計ジャッジ時間 | 3,581 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 WA * 24 |
ソースコード
#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;
}
Kiona0405