def rem(r,c):
global m,n
a[r][c] = 0
i = c-1
while i>0 and(a[r][i] == 1 or a[r][i] == 3):
a[r][i] -= 1
i -=1
i = c+1
while i<n and (a[r][i] == 1 or a[r][i] == 3) != 0:
a[r][i] -= 1
i +=1
i = r-1
while i>0 and(a[i][c] == 2 or a[i][c] == 3):
a[i][c] -= 2
i = r+1
while i <m and(a[i][c] == 2 or a[i][c] == 3):
a[i][c] -= 2
i += 1
def add(r,c):
global m,n
if a[r][c]!= 2 or a[r][c] !=3:
r2 = r-1
while r2>0 and a[r2][c] !=4:
r2 -= 1
if r2 > 0:
for i in range(r-1,r2,-1):
a[i][c] += 2
r2 = r+1
while r2<m and a[r2][c] !=4:
r2 +=1
if r2<m:
for i in range(r+1,r2,1):
a[i][c] += 2
if a[r][c] !=1 or a[r][c]!=3:
c2 = c-1
while c2>0 and c2!=4:
c2 -= 1
if c2>=0:
for i in range(c-1,c2,-1):
a[r][i] +=1
c2 = c+1
while c2<n and a[r][c2]!=4:
c2 += 1
if c2<n:
for i in range(c+1,c2,1):
a[r][i] +=1
a[r][c] = 4
imax = 0
m,n,h = map(int,input().split())
a = [[0]*n for j in range(m)]
for i in range(h):
r,c,indel = map(int,input().split())
if indel == 0:
add(r,c)
else:
rem(r,c)
total = 0
for i in range(m):
total += n - a[i].count(0)
if total>imax :
imax = total
print(imax)
print(total)
def rem(r,c):
global m,n
a[r][c] = 0
i = c-1
while i>0 and(a[r][i] == 1 or a[r][i] == 3):
a[r][i] -= 1
i -=1
i = c+1
while i a[r][i] -= 1
i +=1
i = r-1
while i>0 and(a[i][c] == 2 or a[i][c] == 3):
a[i][c] -= 2
i = r+1
while i a[i][c] -= 2
i += 1
def add(r,c):
global m,n
if a[r][c]!= 2 or a[r][c] !=3:
r2 = r-1
while r2>0 and a[r2][c] !=4:
r2 -= 1
if r2 > 0:
for i in range(r-1,r2,-1):
a[i][c] += 2
r2 = r+1
while r2 r2 +=1
if r2 for i in range(r+1,r2,1):
a[i][c] += 2
if a[r][c] !=1 or a[r][c]!=3:
c2 = c-1
while c2>0 and c2!=4:
c2 -= 1
if c2>=0:
for i in range(c-1,c2,-1):
a[r][i] +=1
c2 = c+1
while c2 c2 += 1
if c2 for i in range(c+1,c2,1):
a[r][i] +=1
a[r][c] = 4
imax = 0
m,n,h = map(int,input().split())
a = [[0]*n for j in range(m)]
for i in range(h):
r,c,indel = map(int,input().split())
if indel == 0:
add(r,c)
else:
rem(r,c)
total = 0
for i in range(m):
total += n - a[i].count(0)
if total>imax :
imax = total
print(imax)
print(total)
連線的程式碼有問題吧,如果上下左右沒有木樁就不連線