結果

問題 No.1078 I love Matrix Construction
ユーザー SalmonizeSalmonize
提出日時 2020-06-12 22:17:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,703 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 11,160 KB
実行使用メモリ 157,232 KB
最終ジャッジ日時 2023-09-06 10:36:35
合計ジャッジ時間 16,600 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 17 ms
8,040 KB
testcase_02 AC 175 ms
30,048 KB
testcase_03 AC 550 ms
64,920 KB
testcase_04 AC 807 ms
86,528 KB
testcase_05 WA -
testcase_06 AC 174 ms
29,292 KB
testcase_07 AC 69 ms
16,408 KB
testcase_08 AC 667 ms
73,424 KB
testcase_09 WA -
testcase_10 AC 1,799 ms
157,232 KB
testcase_11 AC 858 ms
91,020 KB
testcase_12 AC 1,396 ms
131,676 KB
testcase_13 AC 1,563 ms
147,220 KB
testcase_14 AC 1,053 ms
104,240 KB
testcase_15 AC 1,499 ms
139,644 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 139 ms
24,016 KB
testcase_19 AC 327 ms
44,568 KB
testcase_20 AC 317 ms
43,992 KB
testcase_21 AC 23 ms
9,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def SCC(N, G, RG):
    order = []
    used = [0]*N
    group = [None]*N

    def dfs(s):
        used[s] = 1
        for t in G[s]:
            if not used[t]:
                dfs(t)
        order.append(s)

    def rdfs(s, col):
        group[s] = col
        used[s] = 1
        for t in RG[s]:
            if not used[t]:
                rdfs(t, col)

    for i in range(N):
        if not used[i]:
            dfs(i)
    used = [0]*N
    label = 0
    for s in reversed(order):
        if not used[s]:
            rdfs(s, label)
            label += 1
    return label, group

def solve():
    n = ni()
    s = [x-1 for x in nl()]
    t = [x-1 for x in nl()]
    u = nl()
    m = 2 * n ** 2
    G = [list() for _ in range(m)]
    rG = [list() for _ in range(m)]
    for i in range(n):
        cs, ct, cu = s[i], t[i], u[i]
        for j in range(n):
            x = [cs * n + j, cs * n + j + n**2]
            y = [j * n + ct, j * n + ct + n**2]
            G[x[cu & 1]].append(y[(cu >> 1) ^ 1])
            rG[y[(cu >> 1) ^ 1]].append(x[cu & 1])
            G[y[cu >> 1]].append(x[cu & 1 ^ 1])
            rG[x[cu & 1 ^ 1]].append(y[cu >> 1])
    _, gr = SCC(m, G, rG)
    ret = [0]*n**2
    for i in range(n**2):
        if gr[i] == gr[i+n**2]:
            print(-1)
            return
        ret[i] = int(gr[i] > gr[i+n**2])
    for i in range(n):
        print(*ret[i*n:(i+1)*n])
    return

solve()
0