結果
問題 |
No.2255 Determinant Sum
|
ユーザー |
|
提出日時 | 2023-03-25 12:18:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 2,188 bytes |
コンパイル時間 | 2,329 ms |
コンパイル使用メモリ | 202,784 KB |
最終ジャッジ日時 | 2025-02-11 18:02:08 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
// 提出時にassertはオフ #ifndef DEBUG #ifndef NDEBUG #define NDEBUG #endif #endif #include <bits/stdc++.h> using namespace std; using ll = long long; #define ALL(x) (x).begin(), (x).end() template <class T> using vec = vector<T>; void solve() { int N, P; cin >> N >> P; vec<vec<int>> A(N, vec<int>(N)); for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { cin >> A[i][j]; } } if(P != 2) { cout << 0 << "\n"; return; } // P = 2 の場合 bool haveTwoWildInRowOrCol = false; vec<int> noWildRow, noWildCol; for(int i = 0; i < N; i++) { int cnt = 0; for(int j = 0; j < N; j++) { if(A[i][j] == -1) { ++cnt; } } if(cnt >= 2) { haveTwoWildInRowOrCol = true; } else if(cnt == 0) { noWildRow.push_back(i); } } for(int j = 0; j < N; j++) { int cnt = 0; for(int i = 0; i < N; i++) { if(A[i][j] == -1) { ++cnt; } } if(cnt >= 2) { haveTwoWildInRowOrCol = true; } else if(cnt == 0) { noWildCol.push_back(j); } } if(haveTwoWildInRowOrCol) { cout << 0 << "\n"; return; } if(noWildCol.empty()) { cout << 1 << "\n"; return; } // xor基底を求める vec<ll> basis_candidate; for(int col : noWildCol) { ll beki = 1; ll num = 0; for(int row : noWildRow) { assert(A[row][col] != -1); num += beki * A[row][col]; beki <<= 1; } basis_candidate.push_back(num); } vec<ll> basis; for(ll v : basis_candidate) { for(ll e : basis) { v = min(v, v ^ e); } if(v > 0) { basis.push_back(v); } } if(basis.size() == basis_candidate.size()) { cout << 1 << "\n"; } else { cout << 0 << "\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; for(int _ = 0; _ < T; _++) { solve(); } }