結果

問題 No.2255 Determinant Sum
ユーザー sotanishysotanishy
提出日時 2023-03-24 22:19:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 81,744 KB
実行使用メモリ 76,612 KB
最終ジャッジ日時 2023-10-18 21:13:16
合計ジャッジ時間 3,138 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,484 KB
testcase_01 AC 38 ms
53,484 KB
testcase_02 AC 45 ms
61,508 KB
testcase_03 AC 45 ms
61,508 KB
testcase_04 AC 49 ms
61,948 KB
testcase_05 AC 41 ms
53,484 KB
testcase_06 AC 78 ms
75,408 KB
testcase_07 AC 129 ms
76,300 KB
testcase_08 AC 111 ms
76,404 KB
testcase_09 AC 122 ms
76,352 KB
testcase_10 AC 72 ms
75,376 KB
testcase_11 AC 55 ms
72,288 KB
testcase_12 AC 71 ms
75,668 KB
testcase_13 AC 67 ms
75,696 KB
testcase_14 AC 167 ms
76,480 KB
testcase_15 AC 109 ms
76,156 KB
testcase_16 AC 69 ms
75,620 KB
testcase_17 AC 108 ms
76,280 KB
testcase_18 AC 68 ms
75,736 KB
testcase_19 AC 66 ms
75,688 KB
testcase_20 AC 75 ms
75,784 KB
testcase_21 AC 106 ms
76,612 KB
testcase_22 AC 71 ms
75,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def det2(A):
    if not A:
        return 1
    n = len(A)
    pivot = 0
    for j in range(n):
        i = pivot
        while i < n and A[i][j] == 0:
            i += 1
        if i == n:
            return 0
        if i != pivot:
            A[i], A[pivot] = A[pivot], A[i]

        for k in range(n):
            if k == pivot:
                continue
            if A[k][j]:
                for l in range(j, n):
                    A[k][l] ^= A[pivot][l]

        pivot += 1
    return 1

T = int(input())
for _ in range(T):
    N, P = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    if P >= 3:
        print(0)
    else:
        row = [0] * N
        col = [0] * N
        ok = True
        for i in range(N):
            for j in range(N):
                if A[i][j] == -1:
                    if row[i] or col[j]:
                        ok = False
                        break
                    row[i] = 1
                    col[j] = 1
            if not ok:
                break

        if not ok:
            print(0)
        else:
            M = N - sum(row)
            rs = [i for i in range(N) if not row[i]]
            cs = [j for j in range(N) if not col[j]]
            rem = [[0] * M for _ in range(M)]
            for ni, i in enumerate(rs):
                for nj, j in enumerate(cs):
                    rem[ni][nj] = A[i][j]
            print(det2(rem))
0