結果

問題 No.1078 I love Matrix Construction
ユーザー QCFiumQCFium
提出日時 2020-05-02 18:02:15
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,350 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 292,376 KB
最終ジャッジ日時 2023-08-29 01:29:33
合計ジャッジ時間 16,124 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,260 KB
testcase_01 AC 75 ms
71,432 KB
testcase_02 AC 400 ms
98,108 KB
testcase_03 AC 711 ms
168,076 KB
testcase_04 AC 912 ms
206,704 KB
testcase_05 AC 736 ms
133,076 KB
testcase_06 RE -
testcase_07 AC 276 ms
87,720 KB
testcase_08 RE -
testcase_09 AC 219 ms
85,536 KB
testcase_10 RE -
testcase_11 AC 989 ms
234,128 KB
testcase_12 AC 1,162 ms
245,028 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 280 ms
84,836 KB
testcase_17 AC 71 ms
71,080 KB
testcase_18 AC 354 ms
95,272 KB
testcase_19 AC 485 ms
148,476 KB
testcase_20 AC 529 ms
157,060 KB
testcase_21 AC 132 ms
78,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(N) :
	a[i] -= 1
	b[i] -= 1

def INDEX(i, j, k) : return (i * N + j) * 2 + k
hen = [[] for i in range(N * N * 2)]
rev = [[] for i in range(N * N * 2)]
for i in range(N) :
	r0 = c[i] % 2
	r1 = c[i] // 2
	for j in range(N) :
		hen[INDEX(a[i], j, r0)].append(INDEX(j, b[i], not r1));
		rev[INDEX(j, b[i], not r1)].append(INDEX(a[i], j, r0));
		hen[INDEX(j, b[i], r1)].append(INDEX(a[i], j, not r0));
		rev[INDEX(a[i], j, not r0)].append(INDEX(j, b[i], r1));

visited = [False for i in range(N * N * 2)]
ord = []

def dfs0(i) :
	visited[i] = True
	for j in hen[i] :
		if not visited[j] : dfs0(j)
	ord.append(i)

group = [-1 for i in range(N * N * 2)]
group_cnt = 0

def dfs1(i) :
	group[i] = group_cnt
	for j in rev[i] :
		if group[j] == -1 : dfs1(j)

for i in range(N * N * 2) :
	if not visited[i] : dfs0(i)
ord = ord[::-1]
for i in ord :
	if group[i] == -1 :
		dfs1(i)
		group_cnt += 1

possible = True
for i in range(N) :
	for j in range(N) :
		if group[INDEX(i, j, 0)] == group[INDEX(i, j, 1)] : possible = False

if not possible :
	print("-1")
else :
	for i in range(N) :
		for j in range(N) :
			if j : print(' ', end = '')
			print(int(group[INDEX(i, j, 0)] < group[INDEX(i, j, 1)]), end = '')
		print('')

0