結果

問題 No.1434 Make Maze
ユーザー mkawa2mkawa2
提出日時 2021-03-19 23:42:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,378 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 101,408 KB
最終ジャッジ日時 2024-04-29 19:40:41
合計ジャッジ時間 6,671 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,992 KB
testcase_01 AC 42 ms
52,608 KB
testcase_02 AC 179 ms
101,376 KB
testcase_03 AC 179 ms
101,408 KB
testcase_04 AC 39 ms
53,352 KB
testcase_05 AC 41 ms
52,608 KB
testcase_06 AC 38 ms
53,248 KB
testcase_07 AC 41 ms
53,248 KB
testcase_08 AC 39 ms
53,012 KB
testcase_09 AC 40 ms
52,736 KB
testcase_10 AC 40 ms
53,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 45 ms
60,032 KB
testcase_14 AC 95 ms
78,208 KB
testcase_15 AC 125 ms
83,572 KB
testcase_16 AC 100 ms
78,884 KB
testcase_17 AC 95 ms
77,696 KB
testcase_18 AC 106 ms
79,872 KB
testcase_19 AC 144 ms
89,764 KB
testcase_20 AC 40 ms
54,272 KB
testcase_21 AC 43 ms
58,880 KB
testcase_22 AC 42 ms
56,832 KB
testcase_23 AC 38 ms
52,992 KB
testcase_24 AC 122 ms
85,732 KB
testcase_25 AC 151 ms
92,928 KB
testcase_26 AC 105 ms
78,116 KB
testcase_27 AC 137 ms
85,728 KB
testcase_28 AC 98 ms
78,464 KB
testcase_29 AC 79 ms
77,164 KB
testcase_30 AC 104 ms
79,936 KB
testcase_31 AC 112 ms
79,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7

class UnionFind:
    def __init__(self, n):
        self.state = [-1]*n
        self.size_table = [1]*n
        # cntはグループ数
        self.cnt = n

    def root(self, u):
        v = self.state[u]
        if v < 0: return u
        self.state[u] = res = self.root(v)
        return res

    def merge(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if ru == rv: return
        du = self.state[ru]
        dv = self.state[rv]
        if du > dv: ru, rv = rv, ru
        if du == dv: self.state[ru] -= 1
        self.state[rv] = ru
        self.cnt -= 1
        self.size_table[ru] += self.size_table[rv]
        return

    # グループの要素数
    def size(self, u):
        return self.size_table[self.root(u)]

H, W, x = LI()
h, w = (H+1)//2, (W+1)//2
uf = UnionFind(H*W)
mn = H+W-2
mx = (h*w-1)*2 if h & 1 or w & 1 else (h*w-2)*2

if x & 1 or x > mx or x < mn or x%4 != mx%4:
    print(-1)
    exit()

tt = [[-1]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i & 1 == 0 and j & 1 == 0: tt[i][j] = 0
        if i & 1 and j & 1: tt[i][j] = 1

i = j = 0
di, dj = 0, 1
zgzg = False
while 1:
    if H-1-i+W-1-j == x: break
    if zgzg:
        if i == W-3:
            if j%4: di, dj = 0, 1
            else: di, dj = 1, 0
        else:
            if j%4: di, dj = -1, 0
            else: di, dj = 0, 1
    else:
        if j == W-1:
            if i%4 == 0: di, dj = 1, 0
            else: di, dj = 0, -1
        elif j == 0:
            if i%4: di, dj = 1, 0
            else: di, dj = 0, 1

    u = i*W+j
    v = (i+di*2)*W+j+dj*2
    uf.merge(u, v)
    i, j = i+di, j+dj
    tt[i][j] = 0
    i, j = i+di, j+dj
    tt[i][j] = 0
    x -= 2
    if h & 1 == 0 and i == H-3: zgzg = True

while i+2 < H and tt[i+1][j] == -1:
    u = i*W+j
    v = (i+2)*W+j
    uf.merge(u, v)
    tt[i+1][j] = 0
    i += 2
while j+2 < W and tt[i][j+1] == -1:
    u = i*W+j
    v = i*W+j+2
    uf.merge(u, v)
    tt[i][j+1] = 0
    j += 2
while i+2 < H and tt[i+1][j] == -1:
    u = i*W+j
    v = (i+2)*W+j
    uf.merge(u, v)
    tt[i+1][j] = 0
    i += 2
# p2D(tt)
# print()

for i in range(0, H, 2):
    for j in range(0, W-2, 2):
        if tt[i][j+1] == 0: continue
        u = i*W+j
        v = i*W+j+2
        if uf.root(u) == uf.root(v): tt[i][j+1] = 1
        else: tt[i][j+1] = 0
        uf.merge(u, v)
for j in range(0, W, 2):
    for i in range(0, H-2, 2):
        if tt[i+1][j] == 0: continue
        u = i*W+j
        v = (i+2)*W+j
        if uf.root(u) == uf.root(v): tt[i+1][j] = 1
        else: tt[i+1][j] = 0
        uf.merge(u, v)
# p2D(tt)

for row in tt:
    print("".join("#" if a else "." for a in row))
0