Problem:


Score : 200 points

Problem Statement

There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.

Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).

Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

If a_i = 1, he painted the region satisfying x < x_i within the rectangle.

If a_i = 2, he painted the region satisfying x > x_i within the rectangle.

If a_i = 3, he painted the region satisfying y < y_i within the rectangle.

If a_i = 4, he painted the region satisfying y > y_i within the rectangle.

Find the area of the white region within the rectangle after he finished painting.

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

0 ≦ x_i ≦ W (1 ≦ i ≦ N)

0 ≦ y_i ≦ H (1 ≦ i ≦ N)

W, H (21:32, added), x_i and y_i are integers.

a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

Input

The input is given from Standard Input in the following format:

W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

Now, the area of the white region within the rectangle is 9.

Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64



Sample input:
5 4 2
2 1 1
3 3 4


Sample output:
9

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
d=[]
for i in range(H):
  d.append([1]*W)
for j in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    for i1 in range(H):
      for x1 in range(x):
        d[i1][x1]=0
  elif a==2:
    for i2 in range(H):
      for x2 in range(x,W):
        d[i2][x2]=0
  elif a==3:
    for i3 in range(y):
      for y1 in range(W):
        d[i3][y1]=0
  else:
    for i4 in range(y,H):
      for y2 in range(W):
        d[i4][y2]=0
ans=0
for k in d:
  ans+=sum(k)
print(ans)

Submission status: Accepted

Solution code:
w, h, n = list(map(int, input().split()))
c = [[] for _ in range(n)]
g = [[0] * w for _ in range(h)]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for H in range(h):
            for W in range(x):
                g[H][W] = 1
    elif a == 2:
        for H in range(h):
            for W in range(x, w):
                g[H][W] = 1
    elif a == 3:
        for H in range(y):
            for W in range(w):
                g[H][W] = 1
    else:
        for H in range(y, h):
            for W in range(w):
                g[H][W] = 1
cnt = 0
for i in g:
    cnt += i.count(0)
print(cnt)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())

white = [0, w, 0, h]

for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    white[0] = max(x, white[0])
  elif a == 2:
    white[1] = min(x, white[1])
  elif a == 3:
    white[2] = max(y, white[2])
  elif a == 4:
    white[3] = min(y, white[3])
if white[1] - white[0] <= 0 or white[3] - white[2] <= 0:
  print(0)
else:
  print((white[1] - white[0]) * (white[3] - white[2]))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
d=[]
for i in range(H):
  d.append([1]*W)
for j in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    for i1 in range(H):
      for x1 in range(x):
        d[i1][x1]=0
  elif a==2:
    for i2 in range(H):
      for x2 in range(x,W):
        d[i2][x2]=0
  elif a==3:
    for i3 in range(y):
      for y1 in range(W):
        d[i3][y1]=0
  else:
    for i4 in range(y,H):
      for y2 in range(W):
        d[i4][y2]=0
ans=0
for k in d:
  ans+=sum(k)
print(ans)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
ls = []
for i in range(N):
    ls.append(list(map(int,input().split())))
sur = [[1]*W for i in range(H)]
for i in range(N):
    if ls[i][2] == 1:
        for j in range(W):
            for k in range(H):
                if j < ls[i][0]:
                    sur[k][j] = 0
    if ls[i][2] == 2:
        for j in range(W):
            for k in range(H):
                if j >= ls[i][0]:
                    sur[k][j] = 0
    if ls[i][2] == 3:
        for j in range(W):
            for k in range(H):
                if k < ls[i][1]:
                    sur[k][j] = 0
    if ls[i][2] == 4:
        for j in range(W):
            for k in range(H):
                if k >= ls[i][1]:
                    sur[k][j] = 0
ans = 0
for i in range(H):
    ans += sur[i].count(1)
print(ans)

Submission status: Accepted

Solution code:
def main():
	W, H, N = map(int, input().split())
	lst = [[True for _ in range(H)] for _ in range(W)]

	for _ in range(N):
		x, y, a = map(int, input().split())

		if a == 1:
			for i in range(x):
				for j in range(H):
					lst[i][j] = False
		elif a == 2:
			for i in range(x, W):
				for j in range(H):
					lst[i][j] = False
		elif a == 3:
			for i in range(W):
				for j in range(y):
					lst[i][j] = False
		elif a == 4:
			for i in range(W):
				for j in range(y, H):
					lst[i][j] = False
		
	cnt = 0

	for i in range(W):
		for j in range(H):
			if lst[i][j]:
				cnt += 1

	print(cnt)

  
if __name__ == "__main__":
  	main()

Submission status: Accepted

Solution code:
import numpy as np
W,H,N=map(int,input().split())

M = np.ones(W*H).reshape(H,W)

for i in range(N):
  x,y,a =map(int,input().split())
  if a==1:
    M[:,:x]=0
  if a==2:
    M[:,x:]=0
  if a==3:
    M[:y,:]=0
  if a==4:
    M[y:,:]=0
  #print(M)
print(int(M.sum()))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())

Z=[[0]*W for _ in range(H)]

for _ in range(N):
    X,Y,a=map(int,input().split())

    if a==1:
        for y in range(H):
            for x in range(0,X):
                Z[y][x]=1
    elif a==2:
        for y in range(H):
            for x in range(X,W):
                Z[y][x]=1
    elif a==3:
        for x in range(W):
            for y in range(0,Y):
                Z[y][x]=1
    else:
        for x in range(W):
            for y in range(Y,H):
                Z[y][x]=1

S=0
for l in Z:
    S+=sum(l)
print(H*W-S)

Submission status: Accepted

Solution code:
def main():
    w, h, n = map(int, input().split())
    minx = miny = 0

    for _ in range(n):
        x, y, a = map(int, input().split())

        if a == 1:
            minx = max(minx, x)
        elif a == 2:
            w = min(w, x)
        elif a == 3:
            miny = max(miny, y)
        else:
            h = min(h, y)
    else:
        print(max(w-minx, 0)*max(h-miny, 0))
        


if __name__ ==  "__main__":
    main()

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1 and x > x1:
    x1 = x
  elif a==2 and x < x2:
    x2 = x
  elif a==3 and y > y1:
    y1 = y
  elif a==4 and y < y2:
    y2 = y
if x1 > x2 or y1 > y2:
  print(0)
else:
  print((x2 - x1)*(y2 - y1))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x1=0
x2=w
y1=0
y2=h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1 and x > x1:
    x1 = x
  elif a==2 and x < x2:
    x2 = x
  elif a==3 and y > y1:
    y1 = y
  elif a==4 and y < y2:
    y2 = y
if x1 > x2 or y1 > y2:
  print(0)
else:
  print((x2 - x1)*(y2 - y1))

Submission status: Accepted

Solution code:
def first(x):
    cnt = 0
    for i in range(1, h+1):
        for j in range(1, x+1):
            if kv[i][j] == 0:
                kv[i][j] = 1
                cnt += 1
    return cnt

def second(x):
    cnt = 0
    for i in range(1, h+1):
        for j in range(x+1, w+1):
            if kv[i][j] == 0:
                kv[i][j] = 1
                cnt += 1
    return cnt

def fourth(y):
    global kv
    cnt = 0
    for i in range(y+1, h+1):
        for j in range(1, w+1):
            if kv[i][j] == 0:
                kv[i][j] = 1
                cnt += 1
    return cnt

def third(y):
    cnt = 0
    for i in range(y, 0, -1):
        for j in range(1, w+1):
            if kv[i][j] == 0:
                kv[i][j] = 1
                cnt += 1
    return cnt


w, h, n = map(int, input().split())

kv = [[0 for _ in range(w+1)] for _ in range(h+1)]
whites = w * h
blacks = 0


for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        blacks += first(x)
    elif a == 2:
        blacks += second(x)
    elif a == 3:
        blacks += third(y)
    elif a== 4:
        blacks += fourth(y)
print(whites-blacks)

Submission status: Accepted

Solution code:
W,H,n = map(int,input().split())
H_ls = [1] * H
W_ls = [1] * W
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        for i in range(x):
            W_ls[i] = 0
    elif a == 2:
        for i in range(x,W):
            W_ls[i] = 0
    elif a == 3:
        for i in range(y):
            H_ls[i] = 0
    else:
        for i in range(y,H):
            H_ls[i] = 0
ans = 0
for x in range(W):
    for y in range(H):
        if H_ls[y] and W_ls[x]:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xya = list(list(map(int, input().split())) for _ in range(n))

left = 0
right = w
down = 0
up = h

for x, y, a in xya:
    if a == 1 and x > left:
        left = x
    if a == 2 and x < right:
        right = x
    if a == 3 and y > down:
        down = y
    if a == 4 and y < up:
        up = y


if right <= left or up <= down:
    ans = 0
else:
    ans = (right - left) * (up - down)

print(ans)

Submission status: Accepted

Solution code:
w, h , n = map(int , input().split())

left = 0
right = w
lower = 0
upper = h

for i in range(n):
  x, y, a = map(int, input().split())
  
  if a == 1:
    left = max(left, x)
  elif a == 2:
    right = min(x, right)
  elif a == 3:
    lower = max(lower, y)
  elif a == 4:
    upper = min(y, upper)

if left > right or lower > upper:
    print(0)
else:
    print((right-left)*(upper-lower))

Submission status: Accepted

Solution code:
w, h, n = list(map(int, input().split()))
left = 0
right = w
lower = 0
upper = h

for i in range(n):
    x, y, a = list(map(int, input().split()))

    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = min(x, right)
    elif a == 3:
        lower = max(lower, y)
    elif a == 4:
        upper = min(y, upper)

if left > right or lower > upper:
    print(0)
else:
    print((right-left)*(upper-lower))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
 
x1 = 0
x2 = w
y1 = 0
y2 = h

for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    x1 = max(x1,x)
  elif a == 2:
    x2 = min(x2,x)
  elif a == 3:
    y1 = max(y1,y) 
  elif a == 4:
    y2 = min(y2,y) 

if x1 >= x2 or y1 >= y2:
    print(0)
else:
    print(abs(x1-x2)*abs(y1-y2))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
l = 0
r = w
u = h
d = 0
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    l = max(l,x)
  elif a == 2:
    r = min(r,x)
  elif a == 3:
    d = max(d,y)
  elif a == 4:
    u = min(u,y)
print(max(r-l,0)*max(u-d,0))

Submission status: Accepted

Solution code:
w, h, n = [int(s) for s in input().split()]
temp_list = [[True] * w for _ in range(h)]
for _ in range(n):
    xs, xe, ys, ye = 0, w, 0, h
    x, y, a = [int(s) for s in input().split()]
    if a == 1:
        xe = x
    elif a == 2:
        xs = x
    elif a == 3:
        ye = y
    elif a == 4:
        ys = y
    for i in range(ys, ye):
        for j in range(xs, xe):
            temp_list[i][j] = False
ans = 0
for i in range(h):
    for j in range(w):
        if temp_list[i][j]:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy

W, H, N = map(int, input().split())
info = []
for _ in range(N):
    x, y, a = map(int, input().split())
    info.append([x,y,a])

plane = numpy.ones((H, W))

for x, y, a in info:
    if a == 1:
        plane[:, :x] = 0
    elif a == 2:
        plane[:, x:] = 0
    elif a == 3:
        plane[:y, :] = 0
    else:
        plane[y:, :] = 0
    
        
print(int(numpy.sum(plane)))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(n)]
l = [["." for i in range(w)] for j in range(h)]
for i in range(n):
    if xya[i][2] == 1:
        l = [["#" if j < xya[i][0] else "#" if l[k][j] == "#" else "." for j in range(w)] for k in range(h)]
    elif xya[i][2] == 2:
        l = [["#" if j >= xya[i][0] else "#" if l[k][j] == "#" else "." for j in range(w)] for k in range(h)]
    elif xya[i][2] == 3:
        l = [["#" if k < xya[i][1] else "#" if l[k][j] == "#" else "." for j in range(w)] for k in range(h)]
    elif xya[i][2] == 4:
        l = [["#" if k >= xya[i][1] else "#" if l[k][j] == "#" else "." for j in range(w)] for k in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if l[i][j] == ".":
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
#x_list = [int(1) for i in range(w+1)]
#y_list = [int(1) for i in range(h+1)]
#print(x_list)
#print(y_list)
min_x = 0
max_x = w
min_y = 0
max_y = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        min_x = max(min_x,x)
    elif a==2:
        max_x = min(max_x,x)
    elif a==3:
        min_y = max(min_y,y)
    else:
        max_y = min(max_y,y)
if min_x > max_x or min_y > max_y:
    print(0)
else:
    print((max_x-min_x)*(max_y-min_y))

Submission status: Accepted

Solution code:
def resolve():
    W, H, M = map(int, input().split())
    x = []
    y = []
    a = []
    a1 = [0]
    a2 = [W]
    a3 = [0]
    a4 = [H]
    for i in range(M):
        X, Y, A = map(int, input().split())
        x.append(X)
        y.append(Y)
        a.append(A)
    for j in range(M):
        if a[j] == 1:
            a1.append(x[j])
        elif a[j] == 2:
            a2.append(x[j])
        elif a[j] == 3:
            a3.append(y[j])
        else:
            a4.append(y[j])
    print((max(min(a4)-max(a3), 0))*(max(min(a2)-max(a1), 0)))
resolve()

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x_min, x_max, y_min, y_max = 0, W, 0, H 
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > x_min:
        x_min = x
    elif a == 2 and x < x_max:
        x_max = x
    elif a == 3 and y > y_min:
        y_min = y
    elif a == 4 and y < y_max:
        y_max = y
if x_max > x_min and y_max > y_min:
    S = (x_max - x_min) * (y_max - y_min)
else:
    S = 0
print(S)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())

a1,a2,a3,a4=0,W,0,H
for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:a1=max(a1,x)
  elif a==2:a2=min(a2,x)
  elif a==3:a3=max(a3,y)
  else:a4=min(a4,y)
    
if a1>=a2 or a3>=a4:
  print(0)
  exit()
if a1>=W or a2<=0 or a3>=H or a4<=0:
  print(0)
  exit()
  
print((a2-a1)*(a4-a3))

Submission status: Accepted

Solution code:
import numpy as np

W, H, N = input().split()
commands = []
for i in range(int(N)):
  commands.append(input().split())
pic = np.zeros((int(W),int(H)))
for com in commands:
  x = int(com[0])
  y = int(com[1])
  a = int(com[2])
  if a==1:
    pic[:x,:] = 1
  if a==2:
    pic[x:,:] = 1
  if a==3:
    pic[:,:y] = 1
  if a==4:
    pic[:,y:] = 1

area = 0

for w in range(int(W)):
  for h in range(int(H)):
    if pic[w,h]==0:
      area += 1
      
print(area)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
m = [[0] * W for _ in range(H)]
for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1: 
    for w in range(x):
      for h in range(H):
        m[h][w] = 1
  elif a == 2:
    for w in range(x , W):
      for h in range(H):
        m[h][w] = 1
  elif a == 3:
    for w in range(W):
      for h in range(y):
        m[h][w] = 1
  else:
    for w in range(W):
      for h in range(y, H):
        m[h][w] = 1
print(sum(m, []).count(0))

Submission status: Accepted

Solution code:
W, H, N = list(map(lambda n: int(n), input().split(" ")))
xmin = [0] # a = 1
xmax = [W] # a = 2
ymin = [0] # a = 3
ymax = [H] # a = 4
for i in range(N):
  tmp = input().split(" ")
  if tmp[2] == "1":
    xmin.append(int(tmp[0]))
  elif tmp[2] == "2":
    xmax.append(int(tmp[0]))
  elif tmp[2] == "3":
    ymin.append(int(tmp[1]))
  elif tmp[2] == "4":
    ymax.append(int(tmp[1]))

S = max([min(xmax) - max(xmin), 0]) * max([min(ymax) - max(ymin), 0])
print(S)

Submission status: Accepted

Solution code:
w,h,n =map(int,input().split())
s =[list(map(int,input().split())) for _ in range(n)]
x =0;y =0;
for i in range(n):
  if s[i][2] ==1:
    if x < s[i][0]: x = s[i][0] 
  elif s[i][2] ==2:
    if w > s[i][0]: w = s[i][0]
  elif s[i][2] ==3:
    if y < s[i][1]: y = s[i][1]
  else:
    if h > s[i][1]: h = s[i][1]
print((w-x)*(h-y) if (w-x)>0 and (h-y)>0 else 0)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
S=w*h
h1=0
w1=0
xmax=0
ymax=0
xmax_r=0
ymax_r=0



for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if xmax<x:
            xmax=x
    
    if a==2:
        if xmax_r<w-x:
            xmax_r=w-x
    
    if a==3:
        if ymax<y:
            ymax=y
    
    if a==4:
        if ymax_r<h-y:
            ymax_r=h-y

if (w-xmax-xmax_r)<=0 or (h-ymax-ymax_r)<=0:
    print("0")
else:
    print((w-xmax-xmax_r)*(h-ymax-ymax_r))

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split())
w=[0]*W
h=[0]*H
for i in range(N):
    x,y,a = map(int, input().split())
    if a==1:
        for i in range(x):
            w[i]=1
    if a==2:
        for i in range(x,W):
            w[i]=1
    if a==3:
        for i in range(y):
            h[i]=1
    if a==4:
        for i in range(y,H):
            h[i]=1
 
print(w.count(0)*h.count(0))

Submission status: Accepted

Solution code:
whn_list = list(map(int,input().split()))
x_y_list = []
x = [0,whn_list[0]]
y = [0,whn_list[1]]

for i in range(whn_list[2]):
    x_y_list.append(list(map(int,input().split())))

for i in x_y_list:
    if i[2] == 1:
        x[0] = max(i[0],x[0])
    elif i[2] == 2:
        x[1] = min(i[0],x[1])
    elif i[2] == 3:
        y[0] = max(i[1],y[0])
    else:
        y[1] = min(i[1],y[1])

s = (x[1]-x[0])*(y[1]-y[0])

if  (x[1] <= x[0]) or (y[1] <= y[0]):
    print(0)
else:
    print(s)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
li=[list(map(int, input().split())) for _ in range(n)]
hi=[0]*h;wi=[0]*w
for i in range(n):
    x=li[i][0]
    y=li[i][1]
    if li[i][2]==1:
        for j1 in range(x):
            wi[j1]=1
    elif li[i][2]==2:
        for j2 in range(x,w):
            wi[j2]=1
    elif li[i][2]==3:
        for j3 in range(y):
            hi[j3]=1
    else:
        for j4 in range(y,h):
            hi[j4]=1
res=w*h
res-=sum(wi)*h
res-=(sum(hi))*(w-sum(wi))
print(res)

Submission status: Accepted

Solution code:
W,H, N = map(int, input().split())
w=[0]*W
h=[0]*H
for i in range(N):
    x,y, a = map(int, input().split())
    if a==1:
        for i in range(x):
            w[i]=1
    if a==2:
        for i in range(x,W):
            w[i]=1
    if a==3:
        for i in range(y):
            h[i]=1
    if a==4:
        for i in range(y,H):
            h[i]=1

print(w.count(0)*h.count(0))

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

w,h,n = map(int, input().split())

s = []

for i in range(h):
    retsu = []
    for j in range(w):
        retsu.append(0)
    s.append(retsu)

for i in range(n):
    x,y,a = map(int, input().split())
    if (a == 1):
        for i in range(h):
            for j in range(x):
                s[i][j] = 1
    elif a == 2:
        for i in range(h):
            for j in range(x,w):
                s[i][j] = 1
    elif a == 3:
        for i in range(y):
            for j in range(w):
                s[i][j] = 1
    else:
        for i in range(y,h):
            for j in range(w):
                s[i][j] = 1

#print(s)

ans = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
W = ["."] * w
H = ["."] * h

for _ in range(n):
  x,y,a = map(int,input().split())
  
  if a==1:
    tmp = ["#"]*x + W[x:]
    W = tmp
  elif a==2:
    tmp = W[:x] + ["#"]
    W = tmp
  elif a==3:
    tmp = ["#"]*y + H[y:]
    H = tmp
  elif a==4:
    tmp = H[:y] + ["#"]
    H = tmp
    
print(W.count('.')*H.count('.'))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
mix=0
mx=w
miy=0
my=h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        mix=max(mix,x)
    elif a==2:
        mx=min(mx,x)
    elif a==3:
        miy=max(miy,y)
    else:
        my=min(my,y)
if mix>=mx or miy>=my:
    print(0)
else:
    print((mx-mix)*(my-miy))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline




def main():
  W,H,M = map(int,input().split())
  x_range = [0,W]
  y_range = [0,H]
  for i in range(M):
    xi,yi,a = map(int,input().split())
    if a == 1:
      x_range[0] = max(x_range[0],xi)
    elif a == 2:
      x_range[1] = min(x_range[1],xi)
    elif a == 3:
      y_range[0] = max(y_range[0],yi)
    elif a == 4:
      y_range[1] = min(y_range[1],yi)
    else:
      raise ValueError
  ans = max(x_range[1] - x_range[0],0)*max(y_range[1] - y_range[0],0)
  print(ans)
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
# Wはx軸、Hはy軸
x_s=0
x_g=W
y_s=0
y_g=H

for i in range(N):
  x,y,a=map(int,input().split())
  # aが1ならxの始点がxiになる
  # aが2ならxの終点がxiになる
  # aが3ならyの始点がyiになる
  # aが4ならyの始点がyiになる
  if a==1:
    if x_s<x:x_s=x
  elif a==2:
    if x_g>x:x_g=x
  elif a==3:
    if y_s<y:y_s=y
  else:
    if y_g>y:y_g=y
if (x_g-x_s) <= 0 or (y_g-y_s)<= 0:
  print(0)
else:
  print((x_g-x_s)*(y_g-y_s))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

w, h, n = map(int, input().split())
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
a = [0 for _ in range(n)]
for i in range(n):
    x[i], y[i], a[i] = map(int, input().split())

masu = [['W' for _ in range(w)] for _ in range(h)]

for i in range(n):
    if 1 == a[i]:
        for j in range(h):
            for k in range(x[i]):
                masu[j][k] = 'B' 
    if 2 == a[i]:
        for j in range(h):
            for k in range(x[i], w): 
                masu[j][k] = 'B' 
    if 3 == a[i]:
        for k in range(y[i]):
            masu[k] = ['B' for _ in range(w)]
    if 4 == a[i]:
        for k in range(y[i], h): 
            masu[k] = ['B' for _ in range(w)]

ans = 0 
for i in range(len(masu)):
    ans += masu[i].count('W')
    # print(masu[i])

print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
WH = [[1]*w for i in range(h)]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(h):
            for j in range(x):
                WH[i][j] = 0
    elif a == 2:
        for i in range(h):
            for j in range(x, w):
                WH[i][j] = 0
    elif a == 3:
        for i in range(y):
            for j in range(w):
                WH[i][j] = 0
    elif a == 4:
        for i in range(y, h):
            for j in range(w):
                WH[i][j] = 0
ans = 0
for i in WH:
    ans += sum(i)
print(ans)

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())

x1,x2,y1,y2 = 0,0,0,0
for _ in range(n):
  x,y,a = map(int, input().split())
  if a == 1: x1 = max(x1, x)
  if a == 2: x2 = max(x2, w-x)
  if a == 3: y1 = max(y1, y)
  if a == 4: y2 = max(y2, h-y)

w -= x1+x2
h -= y1+y2
if w > 0 and h > 0: print(w*h)
else: print(0)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
height = set([])
wigth = set([])
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        for i in range(x):
            wigth.add(i)
    elif a == 2:
        for i in range(x,W):
            wigth.add(i)
    elif a == 3:
        for i in range(y):
            height.add(i)
    else:
        for i in range(y,H):
            height.add(i)
print((H-len(height))*(W-len(wigth)))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
xya=[list(map(int,input().split())) for i in range(N)]

first=[0,0]
last=[W,H]

for i in range(N):
    if first[0]<xya[i][0] and xya[i][2]==1:
        first[0]=xya[i][0]
    if last[0]>xya[i][0] and xya[i][2]==2:
        last[0]=xya[i][0]
    if first[1]<xya[i][1] and xya[i][2]==3:
        first[1]=xya[i][1]
    if last[1]>xya[i][1] and xya[i][2]==4:
        last[1]=xya[i][1]

area=0
if last[0]<=first[0] or last[1]<=first[1]:
    pass
else:
    area=(last[0]-first[0])*(last[1]-first[1])

print(area)

Submission status: Accepted

Solution code:
import itertools

W,H,N=map(int,input().split())
xya=[list(map(int,input().split())) for i in range(N)]
res=[[True for j in range(H)] for i in range(W)]
for j in range(H):
    for i in range(W):
        for k in range(N):
            if (i<xya[k][0] and xya[k][2]==1) or (i>=xya[k][0] and xya[k][2]==2) or (j<xya[k][1] and xya[k][2]==3) or (j>=xya[k][1] and xya[k][2]==4):
                res[i][j]=False
                break
res2=list(itertools.chain.from_iterable(res))

print(res2.count(True))

Submission status: Accepted

Solution code:
#import
#import math
#import numpy as np
#= int(input())
#= input()
W, H, N = map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]
A = [list(map(int, input().split())) for _ in range(N)]
#= {i:[] for i in range(N)}

xmin = 0
xmax = W
ymin = 0
ymax = H

for obj in A:
    x = obj[0]
    y = obj[1]
    a = obj[2]

    if a == 1:
        xmin = max(x, xmin)
    elif a == 2:
        xmax = min(x, xmax)
    elif a == 3:
        ymin = max(y, ymin)
    elif a == 4:
        ymax = min(y, ymax)

x = xmax - xmin
y = ymax - ymin

if x > 0 and y > 0:
    print(x * y)
else:
    print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
region_w = [0, W]
region_h = [0, H]

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        region_w[0] = max(region_w[0], x)
    elif a == 2:
        region_w[1] = min(region_w[1], x)
    elif a == 3:
        region_h[0] = max(region_h[0], y)
    else:
        region_h[1] = min(region_h[1], y)

if (region_w[0] >= region_w[1]) or (region_h[0] >= region_h[1]):
    print(0)
else:
    print((region_w[1]-region_w[0])*(region_h[1]- region_h[0]))

Submission status: Accepted

Solution code:
import numpy as np

W, H, N = map(int, input().split())
F = np.ones((H, W), dtype = int)

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(H):
            for j in range(x):
                if F[i][j] == 1:
                    F[i][j] = 0
    if a == 2:
        for i in range(H):
            for j in range(x, W):
                if F[i][j] == 1:
                    F[i][j] = 0
    if a == 3:
        for i in range(y):
            for j in range(W):
                if F[i][j] == 1:
                    F[i][j] = 0
    if a == 4:
        for i in range(y, H):
            for j in range(W):
                if F[i][j] == 1:
                    F[i][j] = 0

print(sum(sum(F)))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
xl,xr,yh,yl=0,W,H,0
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        xl=max(xl,x)
    elif a==2:
        xr=min(xr,x)
    elif a==3:
        yl=max(yl,y)
    elif a==4:
        yh=min(yh,y)
print(max(xr-xl,0)*max(yh-yl,0))

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

W, H, N = map(int, input().split())

b = [[False] * W for _ in range(H)]

for i in range(N):
    X, Y, A = map(int, input().split())

    h0, h1, w0, w1 = -1, -1, -1, -1
    if A == 1:
        h0, h1, w0, w1 = 0, H, 0, X
    elif A == 2:
        h0, h1, w0, w1 = 0, H, X, W
    elif A == 3:
        h0, h1, w0, w1 = 0, Y, 0, W
    else:
        h0, h1, w0, w1 = Y, H, 0, W

    for x in range(w0, w1):
        for y in range(h0, h1):
            b[y][x] = True

cnt = 0
for y in range(H):
    for x in range(W):
        if not b[y][x]:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())

x_m,x_M,y_m,y_M = 0, W, 0, H

for i in range(N):
    x,y,A = map(int,input().split())
    if A == 1:
        x_m = max(x, x_m)
    if A == 2:
        x_M = min(x, x_M)
    if A == 3:
        y_m = max(y, y_m)
    if A == 4:
        y_M = min(y, y_M)

print(max(0, x_M - x_m) * max(0, y_M - y_m))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
(w, h, n), *q = [[*map(int, i.split())] for i in open(0)]
r = {1: 0, 2: w, 3: 0, 4: h}
for i in q:
    if i[2] == 1:
        r[i[2]] = max(i[0], r[i[2]])
    elif i[2] == 2:
        r[i[2]] = min(i[0], r[i[2]])
    elif i[2] == 3:
        r[i[2]] = max(i[1], r[i[2]])
    elif i[2] == 4:
        r[i[2]] = min(i[1], r[i[2]])
print(
    (r[2] - r[1] if r[2] > r[1] else 0) * (r[4] - r[3] if r[4] > r[3] else 0))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
p = [tuple(map(int, input().split())) for _ in range(n)]

x1 = 0
y1 = 0
x2 = w
y2 = h

for x, y, a in p:
    if a == 1:
        if x > x1:
            x1 = x
    elif a == 2:
        if x < x2:
            x2 = x
    elif a == 3:
        if y > y1:
            y1 = y
    elif a == 4:
        if y < y2:
            y2 = y

if x2-x1 > 0 and y2-y1 > 0:
    print((x2-x1)*(y2-y1))
else:
    print(0)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    w, h, n = map(int, readline().split())

    x_max = w
    x_min = 0
    y_max = h
    y_min = 0

    for _ in range(n):
        x, y, a = map(int, readline().split())
        if a == 1:
            x_min = max(x_min, x)
        elif a == 2:
            x_max = min(x_max, x)
        elif a == 3:
            y_min = max(y_min, y)
        else:
            y_max = min(y_max, y)

    print(max(0, (x_max - x_min)) * max(0, (y_max - y_min)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
a = [[0], [w], [0], [h]]
for _ in range(n):
    x, y, z = map(int, input().split())
    if z == 1 or z == 2:
        a[z-1].append(x)
    else:
        a[z-1].append(y)

dx = min(a[1]) - max(a[0])
dy = min(a[3]) - max(a[2])

if dx <= 0 or dy <= 0:
    print(0)
else:
    print(dx * dy)