結果

問題 No.2255 Determinant Sum
ユーザー noya2
提出日時 2023-03-13 17:28:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 203,792 KB
最終ジャッジ日時 2025-02-11 10:56:23
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
using namespace std;

void solve(){
    int n, p; cin >> n >> p;
    vector<vector<int>> a(n,vector<int>(n));
    rep(i,n) rep(j,n) cin >> a[i][j];
    if (p != 2){
        cout << 0 << endl;
        return ;
    }
    vector<int> rs, cs;
    rep(i,n){
        int cnt = 0;
        rep(j,n){
            if (a[i][j] == -1) cnt++;
        }
        if (cnt >= 2){
            cout << 0 << endl;
            return ;
        }
        if (cnt == 0){
            rs.emplace_back(i);
        }
    }
    rep(j,n){
        int cnt = 0;
        rep(i,n){
            if (a[i][j] == -1) cnt++;
        }
        if (cnt >= 2){
            cout << 0 << endl;
            return ;
        }
        if (cnt == 0){
            cs.emplace_back(j);
        }
    }
    vector<long long> bs;
    for (int i : rs){
        long long x = 0;
        for (int j : cs){
            x <<= 1;
            x += a[i][j];
        }
        for (long long b : bs){
            x = min(x,x^b);
        }
        if (x == 0){
            cout << 0 << endl;
            return ;
        }
        bs.emplace_back(x);
    }
    cout << 1 << endl;
}

int main(){
    int t; cin >> t;
    while(t--) solve();
}
0