結果

問題 No.1078 I love Matrix Construction
ユーザー neterukunneterukun
提出日時 2020-06-12 23:19:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,440 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 134,812 KB
最終ジャッジ日時 2023-09-06 11:22:45
合計ジャッジ時間 11,381 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,968 KB
testcase_01 AC 75 ms
71,308 KB
testcase_02 AC 214 ms
85,992 KB
testcase_03 AC 320 ms
99,424 KB
testcase_04 AC 371 ms
108,140 KB
testcase_05 WA -
testcase_06 AC 212 ms
86,160 KB
testcase_07 AC 179 ms
80,200 KB
testcase_08 AC 341 ms
102,832 KB
testcase_09 WA -
testcase_10 AC 550 ms
134,812 KB
testcase_11 AC 394 ms
109,892 KB
testcase_12 AC 503 ms
124,996 KB
testcase_13 AC 524 ms
131,324 KB
testcase_14 AC 422 ms
114,600 KB
testcase_15 AC 525 ms
128,548 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 197 ms
83,792 KB
testcase_19 AC 260 ms
91,820 KB
testcase_20 AC 257 ms
91,560 KB
testcase_21 AC 113 ms
77,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_bipartite(graph, s):
    """頂点sを含むgraphが二部グラフかどうかを判定する"""
    n = len(graph)
    stack = [s]
    used[s] = 0
    while stack:
        v = stack.pop()
        for nxt_v in graph[v]:
            if used[nxt_v] == -1:
                used[nxt_v] = used[v] ^ 1
                stack.append(nxt_v)
            elif used[nxt_v] ^ used[v] == 0:
                return False
    return True

def to_ind(i, j, lr):
    if lr == 0:
        ans = i * n + j + n ** 2
    else:
        ans = i * n + j
    return ans

n = int(input())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
u = list(map(int, input().split()))

graph = [[] for i in range(2 * n * n)]
for i in range(n):
    for j in range(n):
        si = s[i] - 1
        ti = t[i] - 1
        ul, ur = u[i] % 2, u[i] // 2
        graph[to_ind(si, j, ul)].append(to_ind(j, ti, ur))
        graph[to_ind(j, ti, ur)].append(to_ind(si, j, ul))

for i in range(n ** 2):
    graph[i].append(i + n ** 2)
    graph[i + n ** 2].append(i)

flag = True
used = [-1] * (2 * n * n)
for i in range(2 * n * n):
    if used[i] != -1:
        continue
    flag &= is_bipartite(graph, i)

if not flag:
    print(-1)
    exit()

ans = [[0] * n for i in range(n)]

for i in range(n):
    for j in range(n):
        if used[to_ind(i, j, 0)] == 0:
            ans[i][j] = 1
        else:
            ans[i][j] = 0
for res in ans:
    print(*res)
0