# 動線安排 - AC90% WA10%
# https://zerojudge.tw/ShowProblem?problemid=g596
from sys import stdin
e = stdin.readline
def P():
return # 快把我註解掉~~
s = ["_", "-", "|", "+", "@", " "]
[print(" ".join([s[j] for j in i[:-1]])) for i in l[:-1]]
print("cnt", cnt)
print("ans", ans)
print()
m, n, h = map(int, e().split())
l = [[0] * n + [-1] for i in range(m)] + [[-1] * n] # -1為邊界
ans = 0
cnt = 0
d = [(0, 1), (0, -1), (1, 0), (-1, 0)]
for _ in range(h):
r, c, t = map(int, e().split())
if t: # remove
l[r][c] = 0 ; cnt -= 1 # 拔掉柱子
for dx, dy in d: # 四個方向都試一遍
nx, ny = r + dx, c + dy
while l[nx][ny] != -1: # 出界就淘汰啦
if l[nx][ny] == 4: break # 碰到柱子就停
if dx == 0: # 現在橫著走
if l[nx][ny] == 1: l[nx][ny] = 0 ; cnt -= 1 # - -> _
if l[nx][ny] == 3: l[nx][ny] = 2 # + -> |
if dy == 0: # 現在直著走
if l[nx][ny] == 2: l[nx][ny] = 0 ; cnt -= 1 # | -> _
if l[nx][ny] == 3: l[nx][ny] = 1 # + -> -
nx += dx
ny += dy
else: # add
if l[r][c] == 0: cnt += 1 # 原本是空地才+1
l[r][c] = 4 # 插下柱子
for dx, dy in d: # 四個方向都試一遍
stack = [] # 用來記錄可能要放線的座標 他不是stack但我懶得改名子
nx, ny = r + dx, c + dy
while l[nx][ny] != -1: # 出界就淘汰啦
if l[nx][ny] == 4: # 碰到柱子 代表可以連線
for x, y in stack: # 把剛剛紀錄的座標都連上線
if l[x][y] == 0: cnt += 1 # 原本是空地才+1
if dx == 0: # 現在橫著走
if l[x][y] == 2: l[x][y] = 3 # | -> +
else: l[x][y] = 1 # _ -> -
if dy == 0: # 現在直著走
if l[x][y] == 1: l[x][y] = 3 # - -> +
else: l[x][y] = 2 # _ -> |
break # 把線連完這個方向就結束
stack.append((nx, ny))
nx += dx
ny += dy
ans = max(cnt, ans)
P()
print(ans)
print(cnt)
# 動線安排 - AC90% WA10%
# https://zerojudge.tw/ShowProblem?problemid=g596
from sys import stdin
e = stdin.readline
def P():
return # 快把我註解掉~~
s = ["_", "-", "|", "+", "@", " "]
[print(" ".join([s[j] for j in i[:-1]])) for i in l[:-1]]
print("cnt", cnt)
print("ans", ans)
print()
m, n, h = map(int, e().split())
l = [[0] * n + [-1] for i in range(m)] + [[-1] * n] # -1為邊界
ans = 0
cnt = 0
d = [(0, 1), (0, -1), (1, 0), (-1, 0)]
for _ in range(h):
r, c, t = map(int, e().split())
if t: # remove
l[r][c] = 0 ; cnt -= 1 # 拔掉柱子
for dx, dy in d: # 四個方向都試一遍
nx, ny = r + dx, c + dy
while l[nx][ny] != -1: # 出界就淘汰啦
if l[nx][ny] == 4: break # 碰到柱子就停
if dx == 0: # 現在橫著走
if l[nx][ny] == 1: l[nx][ny] = 0 ; cnt -= 1 # - -> _
if l[nx][ny] == 3: l[nx][ny] = 2 # + -> |
if dy == 0: # 現在直著走
if l[nx][ny] == 2: l[nx][ny] = 0 ; cnt -= 1 # | -> _
if l[nx][ny] == 3: l[nx][ny] = 1 # + -> -
nx += dx
ny += dy
else: # add
if l[r][c] == 0: cnt += 1 # 原本是空地才+1
l[r][c] = 4 # 插下柱子
for dx, dy in d: # 四個方向都試一遍
stack = [] # 用來記錄可能要放線的座標 他不是stack但我懶得改名子
nx, ny = r + dx, c + dy
while l[nx][ny] != -1: # 出界就淘汰啦
if l[nx][ny] == 4: # 碰到柱子 代表可以連線
for x, y in stack: # 把剛剛紀錄的座標都連上線
if l[x][y] == 0: cnt += 1 # 原本是空地才+1
if dx == 0: # 現在橫著走
if l[x][y] == 2: l[x][y] = 3 # | -> +
else: l[x][y] = 1 # _ -> -
if dy == 0: # 現在直著走
if l[x][y] == 1: l[x][y] = 3 # - -> +
else: l[x][y] = 2 # _ -> |
break # 把線連完這個方向就結束
stack.append((nx, ny))
nx += dx
ny += dy
ans = max(cnt, ans)
P()
print(ans)
print(cnt)
已解決 :)
感謝吳邦一教授~