結果

問題 No.2255 Determinant Sum
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-03-25 12:18:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 2,188 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 210,660 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 23:30:18
合計ジャッジ時間 5,112 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 31 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 16 ms
4,348 KB
testcase_09 AC 16 ms
4,348 KB
testcase_10 AC 23 ms
4,348 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 11 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 18 ms
4,348 KB
testcase_15 AC 12 ms
4,348 KB
testcase_16 AC 13 ms
4,348 KB
testcase_17 AC 12 ms
4,348 KB
testcase_18 AC 9 ms
4,348 KB
testcase_19 AC 10 ms
4,348 KB
testcase_20 AC 11 ms
4,348 KB
testcase_21 AC 11 ms
4,348 KB
testcase_22 AC 10 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 提出時に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();
    }
}
0