結果
問題 | No.1434 Make Maze |
ユーザー | tamato |
提出日時 | 2021-03-19 22:48:30 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,445 bytes |
コンパイル時間 | 162 ms |
コンパイル使用メモリ | 82,660 KB |
実行使用メモリ | 88,888 KB |
最終ジャッジ日時 | 2024-11-19 00:08:53 |
合計ジャッジ時間 | 6,742 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
54,136 KB |
testcase_01 | AC | 37 ms
53,616 KB |
testcase_02 | AC | 225 ms
88,888 KB |
testcase_03 | AC | 221 ms
88,628 KB |
testcase_04 | AC | 39 ms
53,880 KB |
testcase_05 | AC | 37 ms
53,820 KB |
testcase_06 | AC | 36 ms
53,940 KB |
testcase_07 | AC | 38 ms
54,304 KB |
testcase_08 | RE | - |
testcase_09 | AC | 37 ms
53,608 KB |
testcase_10 | AC | 38 ms
53,816 KB |
testcase_11 | AC | 38 ms
55,328 KB |
testcase_12 | RE | - |
testcase_13 | AC | 43 ms
61,224 KB |
testcase_14 | AC | 95 ms
77,016 KB |
testcase_15 | AC | 132 ms
80,848 KB |
testcase_16 | AC | 95 ms
77,408 KB |
testcase_17 | AC | 90 ms
76,692 KB |
testcase_18 | AC | 103 ms
77,676 KB |
testcase_19 | AC | 155 ms
83,196 KB |
testcase_20 | AC | 41 ms
62,152 KB |
testcase_21 | AC | 48 ms
68,088 KB |
testcase_22 | AC | 48 ms
66,776 KB |
testcase_23 | AC | 44 ms
59,480 KB |
testcase_24 | AC | 146 ms
81,468 KB |
testcase_25 | AC | 177 ms
85,056 KB |
testcase_26 | AC | 95 ms
77,484 KB |
testcase_27 | AC | 155 ms
81,292 KB |
testcase_28 | AC | 92 ms
77,016 KB |
testcase_29 | AC | 74 ms
76,348 KB |
testcase_30 | AC | 103 ms
78,072 KB |
testcase_31 | AC | 109 ms
78,160 KB |
ソースコード
mod = 1000000007 eps = 10 ** -9 def main(): import sys input = sys.stdin.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] def fin(): print(-1) exit() def unite(h1, w1, h2, w2): if w1 == w2: grid[(h1 + h2) // 2][w1] = "." else: grid[h1][(w1 + w2) // 2] = "." def cut(h1, w1, h2, w2): if w1 == w2: grid[(h1 + h2) // 2][w1] = "#" else: grid[h1][(w1 + w2) // 2] = "#" H, W, X = map(int, input().split()) grid = [["#"] * W for _ in range(H)] for h in range(H): for w in range(W): if h%2 == 0 and w%2 == 0: grid[h][w] = "." if X & 1: fin() H2 = H // 2 + 1 W2 = W // 2 + 1 X_max = (H2 * W2 - 1) * 2 if H2 % 2 == 0 and W2 % 2 == 0: if X > X_max - 2: fin() else: if X > X_max: fin() if X < (H2 - 1 + W2 - 1) * 2: fin() if ((H2 - 1) + (W2 - 1))%2 == 0: if (X // 2) & 1: fin() else: if (X // 2) % 2 == 0: fin() for w in range(W-2): if w%2 == 0: unite(0, w, 0, w+2) X -= 2 for h in range(H-2): if h%2 == 0: unite(h, W-1, h+2, W-1) X -= 2 if H2 & 1: ww = W-1 hh = 2 while X: X -= 4 unite(hh, ww, hh, ww-2) unite(hh+2, ww, hh+2, ww-2) unite(hh, ww-2, hh+2, ww-2) cut(hh, ww, hh+2, ww) ww -= 2 if ww == 0: ww = W-1 hh += 4 elif W2 & 1: hh = 0 ww = 0 while X: X -= 4 unite(hh, ww, hh+2, ww) unite(hh, ww+2, hh + 2, ww + 2) unite(hh+2, ww, hh+2, ww+2) cut(hh, ww, hh, ww+2) hh += 2 if hh == H-1: hh = 0 ww += 4 else: ww = W - 1 hh = 2 while X: X -= 4 unite(hh, ww, hh, ww - 2) unite(hh + 2, ww, hh + 2, ww - 2) unite(hh, ww-2, hh+2, ww-2) cut(hh, ww, hh + 2, ww) ww -= 2 if ww == 0: ww = W - 1 hh += 4 if hh > H-1: break ww = 0 while X: X -= 4 unite(H-3, ww, H-1, ww) unite(H-3, ww+2, H-1, ww+2) unite(H-3, ww, H-3, ww+2) cut(H-1, ww, H-1, ww+2) ww += 4 UF = UnionFind(H2 * W2) for hh in range(H2): for ww in range(W2): hw = hh * W2 + ww + 1 hw_new_h = hw + W2 if hh != H2-1: if grid[hh * 2 + 1][ww * 2] == ".": UF.unite(hw, hw_new_h) hw_new_w = hw + 1 if ww != W2-1: if grid[hh * 2][ww * 2 + 1] == ".": UF.unite(hw, hw_new_w) for hh in range(H2): for ww in range(W2): hw = hh * W2 + ww + 1 hw_new_h = hw + W2 if hh != H2 - 1: if not UF.isSameGroup(hw, hw_new_h): grid[hh * 2 + 1][ww * 2] = "." UF.unite(hw, hw_new_h) hw_new_w = hw + 1 if ww != W2 - 1: if not UF.isSameGroup(hw, hw_new_w): grid[hh * 2][ww * 2 + 1] = "." UF.unite(hw, hw_new_w) for h in range(H): print("".join(grid[h])) if __name__ == '__main__': main()