結果
問題 | No.2255 Determinant Sum |
ユーザー |
|
提出日時 | 2023-03-25 11:54:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,111 bytes |
コンパイル時間 | 1,903 ms |
コンパイル使用メモリ | 200,444 KB |
最終ジャッジ日時 | 2025-02-11 18:00:38 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 WA * 14 |
ソースコード
// 提出時に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;}// xor基底を求めるvec<ll> basis_candidate;for(int col : noWildCol) {ll beki = 1;ll num = 0;for(int row : noWildCol) {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();}}