結果
問題 | No.803 Very Limited Xor Subset |
ユーザー |
![]() |
提出日時 | 2019-03-19 03:54:47 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 2,493 bytes |
コンパイル時間 | 601 ms |
コンパイル使用メモリ | 68,632 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-21 06:19:15 |
合計ジャッジ時間 | 1,782 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <iostream>#include <vector>#include <utility>#include <algorithm>#define llint long long#define mod 1000000007using namespace std;typedef pair<llint, llint> P;llint n, m, x;llint a[305];vector<P> vec[305];int mat[405][405];int h;void swap(int i, int j){for(int k = 0; k <= n; k++){int t = mat[i][k];mat[i][k] = mat[j][k];mat[j][k] = t;}}void GaussianElimination(){int r = 0;for(int i = 0; i < n && r < h; i++){if(mat[i][r] == 0){int max_val = 0, max_j;for(int j = r+1; j < h; j++){if(mat[j][i] > max_val){max_val = mat[j][i];max_j = j;}}if(max_val == 0) goto end;swap(r, max_j);}for(int j = 0; j < h; j++){if(j == r) continue;if(mat[j][i] == 0) continue;for(int k = 0; k <= n; k++){mat[j][k] ^= mat[r][k];}}r++;end:;}}int main(void){cin >> n >> m >> x;for(int i = 0; i < n; i++) cin >> a[i];llint t, l, r;for(int i = 0; i < m; i++){cin >> t >> l >> r;l--, r--;vec[l].push_back(make_pair(r, t));}for(int i = 0; i < n; i++){sort(vec[i].begin(), vec[i].end());for(int j = 0; j < vec[i].size(); j++){if(vec[i][j].first == vec[i][0].first){if(vec[i][j].second != vec[i][0].second){cout << 0 << endl;return 0;}}else{vec[vec[i][0].first+1].push_back(make_pair(vec[i][j].first, vec[i][0].second^vec[i][j].second));}}}for(int i = 0; i < 30; i++){for(int j = 0; j < n; j++){if(a[j] & (1<<i)) mat[i][j] = 1;else mat[i][j] = 0;}if(x & (1<<i)) mat[i][n] = 1;else mat[i][n] = 0;}h = 30;for(int i = 0; i < n; i++){if(vec[i].size() == 0) continue;//cout << i << " " << vec[i][0].first << " " << vec[i][0].second << endl;for(int j = 0; j < n; j++){if(j >= i && j <= vec[i][0].first) mat[h][j] = 1;else mat[h][j] = 0;}mat[h][n] = vec[i][0].second;h++;}/*for(int i = 0; i < h; i++){for(int j = 0; j <= n; j++){cout << mat[i][j] << " ";}cout << endl;}*/GaussianElimination();/*cout << endl;for(int i = 0; i < h; i++){for(int j = 0; j <= n; j++){cout << mat[i][j] << " ";}cout << endl;}*/llint rank = 0;for(int i = 0; i < h; i++){for(int j = 0; j < n; j++){if(mat[i][j]){rank++;goto pass;}}if(mat[i][n]){cout << 0 << endl;return 0;}pass:;}llint ans = 1;for(int i = 0; i < n-rank; i++) ans *= 2, ans %= mod;cout << ans << endl;return 0;}