結果

問題 No.2255 Determinant Sum
ユーザー shobonvipshobonvip
提出日時 2023-03-20 05:44:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 81,624 KB
実行使用メモリ 76,744 KB
最終ジャッジ日時 2023-10-18 20:36:29
合計ジャッジ時間 3,448 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
59,428 KB
testcase_01 AC 38 ms
53,672 KB
testcase_02 AC 75 ms
73,172 KB
testcase_03 AC 76 ms
66,588 KB
testcase_04 AC 75 ms
66,564 KB
testcase_05 AC 42 ms
55,720 KB
testcase_06 AC 138 ms
76,384 KB
testcase_07 AC 113 ms
76,544 KB
testcase_08 AC 109 ms
76,596 KB
testcase_09 AC 112 ms
76,564 KB
testcase_10 AC 147 ms
76,380 KB
testcase_11 AC 114 ms
76,744 KB
testcase_12 AC 99 ms
76,488 KB
testcase_13 AC 110 ms
76,596 KB
testcase_14 AC 114 ms
76,568 KB
testcase_15 AC 118 ms
76,484 KB
testcase_16 AC 117 ms
76,468 KB
testcase_17 AC 117 ms
76,468 KB
testcase_18 AC 101 ms
76,548 KB
testcase_19 AC 96 ms
76,548 KB
testcase_20 AC 110 ms
76,420 KB
testcase_21 AC 115 ms
76,628 KB
testcase_22 AC 102 ms
76,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# これは正式な Validation ではありません(あとでもっと厳密なやつをやる)

def solve(n, p, a):
	if p > 2:
		return 0
	
	x = [0] * n
	y = [0] * n
	for i in range(n):
		for j in range(n):
			if a[i][j] == -1:
				x[i] += 1
				y[j] += 1
	
	mode = 1
	for i in range(n):
		if x[i] > 1 or y[i] > 1:
			mode = 0
			break

	if mode == 0:
		return 0

	bx = []
	by = []
	for i in range(n):
		if x[i] == 0:
			bx.append(i)
		if y[i] == 0:
			by.append(i)

	m = len(bx)
	b = [0] * m
	for i in range(m):
		for j in range(m):
			b[i] ^= a[bx[i]][by[j]] << j
	
	base = []
	for v in b:
		for e in base:
			v = min(v, v^e)
		if v > 0: base.append(v)
	
	if len(base) == m:
		return 1
	else:
		return 0

def isprime(n):
	if n == 1:
		return False
	for i in range(2, int(n**0.5)+1):
		if n % i == 0:
			return False
	return True


T = int(input())
assert 1 <= T <= 100
for i in range(T):
	n, p = map(int,input().split())
	assert 2 <= n <= 50
	assert 2 <= p < 10 ** 9
	assert isprime(p)
	a = [list(map(int,input().split())) for j in range(n)]
	mode = 0
	for i in range(n):
		for j in range(n):
			assert -1 <= a[i][j] < p
			if a[i][j] == -1:
				mode = 1
	assert mode == 1
	print(solve(n,p,a))
0