結果

問題 No.2255 Determinant Sum
ユーザー noya2noya2
提出日時 2023-03-13 17:28:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 211,108 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 20:36:10
合計ジャッジ時間 3,821 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 3 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 102 ms
4,348 KB
testcase_07 AC 34 ms
4,348 KB
testcase_08 AC 33 ms
4,348 KB
testcase_09 AC 35 ms
4,348 KB
testcase_10 AC 72 ms
4,348 KB
testcase_11 AC 19 ms
4,348 KB
testcase_12 AC 24 ms
4,348 KB
testcase_13 AC 16 ms
4,348 KB
testcase_14 AC 41 ms
4,348 KB
testcase_15 AC 30 ms
4,348 KB
testcase_16 AC 39 ms
4,348 KB
testcase_17 AC 30 ms
4,348 KB
testcase_18 AC 21 ms
4,348 KB
testcase_19 AC 22 ms
4,348 KB
testcase_20 AC 30 ms
4,348 KB
testcase_21 AC 22 ms
4,348 KB
testcase_22 AC 23 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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