結果

問題 No.1078 I love Matrix Construction
ユーザー ttrttr
提出日時 2020-06-13 16:45:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,275 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 221,020 KB
最終ジャッジ日時 2023-09-07 20:56:25
合計ジャッジ時間 14,742 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 99 ms
71,572 KB
testcase_02 AC 301 ms
100,460 KB
testcase_03 AC 485 ms
133,956 KB
testcase_04 AC 596 ms
150,392 KB
testcase_05 WA -
testcase_06 AC 306 ms
98,400 KB
testcase_07 AC 229 ms
84,524 KB
testcase_08 AC 616 ms
148,444 KB
testcase_09 WA -
testcase_10 AC 972 ms
221,020 KB
testcase_11 AC 601 ms
156,224 KB
testcase_12 AC 835 ms
205,344 KB
testcase_13 AC 920 ms
216,420 KB
testcase_14 AC 720 ms
176,296 KB
testcase_15 AC 863 ms
205,456 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 276 ms
97,616 KB
testcase_19 AC 364 ms
115,460 KB
testcase_20 AC 367 ms
117,712 KB
testcase_21 AC 146 ms
78,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N = int(input())
S = [int(s)-1 for s in input().split()]
T = [int(t)-1 for t in input().split()]
U = [int(u) for u in input().split()]

M = N**2*2
E = [[] for _ in range(M)]
E2 = [[] for _ in range(M)]
used = [0]*M

for i in range(N):
    for j in range(N):
        l0 = (S[i]*N+j)*2
        l1 = l0+1
        r0 = (j*N+T[i])*2
        r1 = r0+1
        if U[i] == 0:
            E[l0].append(r1)
            E[r0].append(l1)
            E2[l1].append(r0)
            E2[r1].append(l0)
        elif U[i] == 1:
            E[l1].append(r1)
            E[r0].append(l0)
            E2[l0].append(r0)
            E2[r1].append(l1)
        elif U[i] == 2:
            E2[l1].append(r1)
            E2[r0].append(l0)
            E[l0].append(r0)
            E[r1].append(l1)
        else:
            E2[l0].append(r1)
            E2[r0].append(l1)
            E[l1].append(r0)
            E[r1].append(l0)

q = deque()
L = []
for i in range(N):
    for j in range(N):
        for k in range(2):
            ele = []
            n = (i*N+j)*2+k
            if used[n] == 1:
                continue
            q.append(n)
            used[n] = 1
            while q:
                temp = q.pop()
                ele.append(temp)
                for e in E[temp]:
                    if used[e] == 1:
                        continue
                    used[e] = 1
                    q.append(e)
            ele.reverse()
            L.extend(ele)

A = [[0]*N for _ in range(N)]
L.reverse()
L2 = []
q = deque()
for l in L:
    if used[l] == 2:
        continue
    ele = []
    used[l] = 2
    q.append(l)
    while q:
        temp = q.pop()
        ele.append(temp)
        for e in E2[temp]:
            if used[e] == 2:
                continue
            used[e] = 2
            q.append(e)
    L2.append(ele)

L2.reverse()
used = [-1]*M
for i in range(len(L2)):
    ele = L2[i]
    for l in ele:
        if l%2 == 0:
            r = l+1
        else:
            r = l-1
        if used[r] == i:
            A = -1
            break
        if used[r] > i:
            continue
        A[(l//2)//N][(l//2)%N] = l%2
        used[l] = i
    if A == -1:
        break

if A == -1:
    print(A)
else:
    for i in range(N):
        print(*A[i])
0