結果
問題 | No.803 Very Limited Xor Subset |
ユーザー |
![]() |
提出日時 | 2019-04-10 13:11:16 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 3,075 bytes |
コンパイル時間 | 1,422 ms |
コンパイル使用メモリ | 102,488 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-07 03:15:29 |
合計ジャッジ時間 | 2,559 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <iostream>#include <cstdio>#include <fstream>#include <algorithm>#include <string>#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <limits.h>#include <math.h>#include <functional>#include <bitset>#include <iomanip>#include <cassert>#include <float.h>#include <random>#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))#define debug(x) cerr << #x << ": " << x << '\n'#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second<< '\n'using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int,int> Pii;typedef vector<int> vint;typedef vector<ll> vll;const long long INF = INT_MAX;const ll MOD = 1000000007;ll pow_mod(ll x,int n){if(!n)return 1;ll res=pow_mod(x*x%MOD,n/2);if(n&1)res = res*x%MOD;return res%MOD;}const int MAX_ROW = 500; // to be set appropriatelyconst int MAX_COL = 500; // to be set appropriatelystruct BitMatrix {int H, W;bitset<MAX_COL> val[MAX_ROW];BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}inline bitset<MAX_COL>& operator [] (int i) {return val[i];}};int GaussJordan(BitMatrix &A, bool is_extended = false) {int rank = 0;for (int col = 0; col < A.W; ++col) {if (is_extended && col == A.W - 1) break;int pivot = -1;for (int row = rank; row < A.H; ++row) {if (A[row][col]) {pivot = row;break;}}if (pivot == -1) continue;swap(A[pivot], A[rank]);for (int row = 0; row < A.H; ++row) {if (row != rank && A[row][col]) A[row] ^= A[rank];}++rank;}return rank;}int linear_equation(BitMatrix A, vector<int> b) {int m = A.H, n = A.W;BitMatrix M(m, n + 1);for (int i = 0; i < m; ++i) {for (int j = 0; j < n; ++j) M[i][j] = A[i][j];M[i][n] = b[i];}int rank = GaussJordan(M, true);// check if it has no solutionfor (int row = rank; row < m; ++row) if (M[row][n]) return -1;return rank;}ostream &operator<<(ostream &os, BitMatrix &v) {os << "[";for (int i = 0; i < v.H; i++){if (i > 0) os <<endl<< " ";os << "[";for (int j = 0; j < v.W; os << v[i][j++])if (j > 0) os << " ";os << "]";}os << "]";return os;}int main(){ll N,M,X;cin>>N>>M>>X;vint b(M+40,0);BitMatrix B(M+40,N);repeat(i,40){b[i] = (X>>i)&1;}repeat(j,N){ll A;cin>>A;repeat(i,40){B[i][j] = (A>>i)&1;}}repeat(i,M){int l,r;cin>>b[40+i]>>l>>r;l--;r--;//debug(i);for(int j=l;j<=r;j++){B[40+i][j] = 1;}}//debugArray(b,M+40);//cerr<<B<<endl;int rank = linear_equation(B,b);cout << (rank<0? 0:pow_mod(2,N-rank))<<endl;return 0;}