結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 16 ms
8,020 KB
testcase_02 AC 187 ms
30,040 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 WA -
testcase_06 RE -
testcase_07 AC 66 ms
16,500 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 126 ms
24,172 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 23 ms
9,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

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