結果

問題 No.1078 I love Matrix Construction
ユーザー ttrttr
提出日時 2020-06-13 16:02:49
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,274 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 586,404 KB
最終ジャッジ日時 2023-09-07 19:30:25
合計ジャッジ時間 36,490 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 926 ms
469,712 KB
testcase_01 AC 931 ms
469,720 KB
testcase_02 AC 1,156 ms
491,036 KB
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 AC 1,144 ms
489,848 KB
testcase_07 AC 1,080 ms
476,456 KB
testcase_08 MLE -
testcase_09 WA -
testcase_10 TLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 TLE -
testcase_14 MLE -
testcase_15 TLE -
testcase_16 AC 1,070 ms
476,772 KB
testcase_17 AC 959 ms
469,712 KB
testcase_18 AC 1,116 ms
480,756 KB
testcase_19 AC 1,504 ms
497,836 KB
testcase_20 AC 1,427 ms
498,112 KB
testcase_21 AC 976 ms
472,200 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 = 5*10**6
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]*10**4+j*10
        l1 = l0+1
        r0 = j*10**4+T[i]*10
        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*10**4+j*10+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()
cnt = 2
for ele in L2:
    cnt += 1
    for l in ele:
        if l%2 == 0:
            r = l+1
        else:
            r = l-1
        if used[r] == cnt:
            A = -1
            break
        if used[r] > 2:
            continue
        A[l//10**4][(l%10**4)//10] = l%2
        used[l] = cnt
    if A == -1:
        break

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