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())

x = [0]*N
y = [0]*N
a = [0]*N
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())

left_x = [0]
right_x = [W]
down_y = [0]
up_y = [H]

for i in range(N):
    if a[i] == 1:
        left_x.append(x[i])
    elif a[i] == 2:
        right_x.append(x[i])
    elif a[i] == 3:
        down_y.append(y[i])
    elif a[i] == 4:
        up_y.append(y[i])

w = min(right_x) - max(left_x)
h = min(up_y) - max(down_y)

if w <= 0 or h <= 0:
    print(0)
else:
    print(w*h)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xa = 0
xb = w
ya = 0
yb = h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        xa = max(x, xa)
    if a == 2:
        xb = min(x, xb)
    if a == 3:
        ya = max(y, ya)
    if a == 4:
        yb = min(y, yb)
        
print(max(max(xb - xa, 0) * max(yb - ya, 0), 0))

Submission status: Accepted

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

border = [0,W,0,H]

for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    border[a-1] = max(border[a-1], x)
  elif a == 2:
    border[a-1] = min(border[a-1], x)
  elif a == 3:
    border[a-1] = max(border[a-1], y)
  elif a== 4:
    border[a-1] = min(border[a-1], y)

    
print(max(border[1] - border[0], 0) * max(border[3] - border[2], 0))

Submission status: Accepted

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

border = [0,W,0,H]

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
a1 = [0]
a2 = [w]
a3 = [0]
a4 = [h]

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    else:
        a4.append(y)
        
xl = max(a1)
xh = min(a2)
yl = max(a3)
yh = min(a4)

if xh - xl < 0:
    ansx = 0
else:
    ansx = xh - xl
if yh - yl < 0:
    ansy = 0
else:
    ansy = yh - yl
print(ansx * ansy)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


#----------
W,H,N = list(map(int, input().rstrip().split()))
x_y_a = [list(map(int, input().rstrip().split())) for _ in range(N)]
#----------
x_max,y_max = W,H
x_min,y_min = 0,0

for x,y,a in x_y_a:
    if a == 1 and x_min < x:
        x_min = x
    elif a == 2 and x_max > x:
        x_max = x
    elif a == 3 and y_min < y:
        y_min = y
    elif a == 4 and y_max > y:
        y_max = y
    
if (x_max >= x_min) and (y_max >= y_min):
    area = (x_max - x_min) * (y_max - y_min)
else:
    area = 0

print(area)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
list_w=[1]*w
list_h=[1]*h

for i in range(n):
	if a[i][2]==1:
		for j in range(a[i][0]):
			list_w[j]=0
	elif a[i][2]==2:
		for j in range(w-1,a[i][0]-1,-1):
			list_w[j]=0
	elif a[i][2]==3:
		for j in range(a[i][1]):
			list_h[j]=0		
	elif a[i][2]==4:
		for j in range(h-1,a[i][1]-1,-1):
			list_h[j]=0

h=list_h.count(1)
w=list_w.count(1)
print(h*w)

Submission status: Accepted

Solution code:
#ABC047

w,h,n = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]

x = [0,w,0,h]#[l,r,b,t]

for i in range(n):
    if l[i][2] == 1:
        x[0] = max(x[0],l[i][0])
    elif l[i][2] == 2:
        x[1] = min(x[1],l[i][0])
    elif l[i][2] == 3:
        x[2] = max(x[2],l[i][1])
    else:
        x[3] = min(x[3],l[i][1])
    
    #print(x)
    if x[0] >= x[1] or x[2] >= x[3]:
        print(0)
        break
        
        
if x[0] < x[1] and x[2] < x[3]:
    print((x[1]-x[0])*(x[3]-x[2]))

Submission status: Accepted

Solution code:
w, h, n=map(int, input().split())
xa=0
xb=w
ya=0
yb=h
for _ in range(n):
  x, y, a=map(int, input().split())
  if a==1:
    xa=max(x, xa)
  if a==2:
    xb=min(x, xb)
  if a==3:
    ya=max(y, ya)
  if a==4:
    yb=min(y, yb)
    
print(max(max(xb-xa, 0)*max(yb-ya, 0), 0))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
input_li = [list(map(int, input().split())) for i in range(N)]
dic = {"1" : 0, "2": W, "3" : 0, "4" : H}
for l in input_li :
    if l[2] == 1 and dic[str(l[2])] < l[0] :
        dic[str(l[2])] = l[0]
    if l[2] == 2 and dic[str(l[2])] > l[0] :
        dic[str(l[2])] = l[0]
    if l[2] == 3 and dic[str(l[2])] < l[1] :
        dic[str(l[2])] = l[1]
    if l[2] == 4 and dic[str(l[2])] > l[1] :
        dic[str(l[2])] = l[1]
if dic["2"] - dic["1"] < 0 and dic["4"] - dic["3"] < 0 :
    print(0)
else :
    print(max(0, (dic["2"] - dic["1"]) * (dic["4"] - dic["3"])))

Submission status: Accepted

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

xmin, xmax, ymin, ymax = 0,w,0,h

for i in range(n):
    xi,yi,ai = map(int, input().split())
    if ai == 1:
        if xmin < xi:
            xmin = xi
    if ai == 2:
        if xmax > xi:
            xmax = xi
    if ai == 3:
        if ymin < yi:
            ymin = yi
    if ai == 4:
        if ymax > yi:
            ymax = yi

if xmax < xmin or ymax < ymin:
    menseki = 0
else:
    menseki = (xmax-xmin) * (ymax-ymin)
print(menseki)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
b=[0,w,0,h]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        b[0]=max(b[0],x)
    elif a==2:
        b[1]=min(b[1],x)
    elif a==3:
        b[2]=max(b[2],y)
    else:
        b[3]=min(b[3],y)
print(max(b[1]-b[0],0)*max(b[3]-b[2],0))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    W, H, N = map(int, input().split())
    dots = [list(map(int, input().split())) for _ in range(N)]
    max_x_left = 0
    min_x_right = W
    max_y_down = 0
    min_y_up = H
    for dot in dots:
        if dot[2] == 1 and dot[0] > max_x_left:
            max_x_left = dot[0]
        elif dot[2] == 2 and dot[0] < min_x_right:
            min_x_right = dot[0]
        elif dot[2] == 3 and dot[1] > max_y_down:
            max_y_down = dot[1]
        elif dot[2] == 4 and dot[1] < min_y_up:
            min_y_up = dot[1]
    if min_x_right <= max_x_left or min_y_up <= max_y_down:
        print(0)
    else:
        print((min_x_right - max_x_left) * (min_y_up - max_y_down))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_left
INF = float("inf")


def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    X = [[0], [W], [0], [H]]
    for i in range(N):
        b = a[i]-1
        if b == 0 or b == 1:
            X[b].append(x[i])
        else:
            X[b].append(y[i])
    lower_x = max(X[0])
    upper_x = min(X[1])
    lower_y = max(X[2])
    upper_y = min(X[3])

    area = max(upper_x-lower_x, 0)*max(upper_y-lower_y, 0)
    print(area)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    a = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
[W, H, N] = list(map(int, input().split()))
[x, y, a] = [ [], [], [] ]
for _ in range(N):
  input_line = list(map(int, input().split()))
  x.append(input_line[0])
  y.append(input_line[1])
  a.append(input_line[2])
area = []
for i in range(W):
  area.append([])
  for j in range(H):
    area[i].append("")
    
for i in range(N):
  if a[i] == 1:
    for X in range(x[i]):
      for Y in range(H):
        area[X][Y] = "f"
  if a[i] == 2:
    for X in range(x[i], W):
      for Y in range(H):
        area[X][Y] = "f"
  if a[i] == 3:
    for X in range(W):
      for Y in range(y[i]):
        area[X][Y] = "f"
  if a[i] == 4:
    for X in range(W):
      for Y in range(y[i], H):
        area[X][Y] = "f"
        
count = 0
for i in range(W):
  for j in range(H):
    if area[i][j] == "":
      count += 1
      
print(count)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
minx,maxx,miny,maxy=0,W,0,H

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        minx=max(x,minx)
    if a==2:
        maxx=min(maxx,x)
    if a==3:
        miny=max(y,miny)
    if a==4:
        maxy=min(y,maxy)

print(max(0,maxx-minx)*max(0,maxy-miny))

Submission status: Accepted

Solution code:
W, H, N = [int(i) for i in input().split(" ")]

a1 = [0,0]
a2 = [W,0]
a3 = [0,0]
a4 = [0,H]

for i in range(0,N):
  lst = [int(i) for i in input().split(" ")]
  if lst[2] == 1:
    a1[0] = max(a1[0],lst[0])
  elif lst[2] == 2:
    a2[0] = min(a2[0],lst[0])
  elif lst[2] == 3:
    a3[1] = max(a3[1],lst[1])
  elif lst[2] == 4:
    a4[1] = min(a4[1],lst[1])

print(max(0,a2[0]-a1[0])*max(0,a4[1]-a3[1]))

Submission status: Accepted

Solution code:
W, H, N = [int(i) for i in input().split(" ")]

a1 = [0,0]
a2 = [W,0]
a3 = [0,0]
a4 = [0,H]

for i in range(0,N):
  lst = [int(i) for i in input().split(" ")]
  if lst[2] == 1 and lst[0] > a1[0]:
    a1[0] = lst[0]
  elif lst[2] == 2 and lst[0] < a2[0]:
    a2[0] = lst[0]
  elif lst[2] == 3 and lst[1] > a3[1]:
    a3[1] = lst[1]
  elif lst[2] == 4 and lst[1] < a4[1]:
    a4[1] = lst[1]

if (a2[0]-a1[0])<0 or (a4[1]-a3[1])<0:
    print(0)
else:
    print((a2[0]-a1[0])*(a4[1]-a3[1]))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x1,x2=0,w
y1,y2=0,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)
print(max((x2-x1)*(y2-y1),0) if x2-x1>0 else 0)

Submission status: Accepted

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

right = W
left = 0
top = H
bottom = 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and left <= x:
        left = x
    elif a == 2 and right >= x:
        right = x
    elif a == 3 and bottom <= y:
        bottom = y
    elif a == 4 and top >= y:
        top = y

if (top-bottom)*(right-left) > 0 and (top-bottom)>0 and (right-left)>0:
    print((top-bottom)*(right-left))
else:
    print(0)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
w,h,n=f()
v=g=0
for _ in range(n):
  x,y,a=f()
  if a==1: v=max(v,x)
  if a==2: w=min(w,x)
  if a==3: g=max(g,y)
  if a==4: h=min(h,y)
print(max(w-v,0)*max(h-g,0))

Submission status: Accepted

Solution code:
f = lambda:map(int,input().split())
w,h,n = f()
lx,rx,ly,ry = 0,w,0,h
for _ in range(n):
  x,y,a = f()
  if a==1:
    lx = max(lx,x)
  if a==2:
    rx = min(rx,x)
  if a==3:
    ly = max(ly,y)
  if a==4:
    ry = min(ry,y)
print(max(rx-lx,0)*max(ry-ly,0))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
A=[[int(i) for i in input().split()] for l in range(n)]
o=[]
for y in range(h):
    p=[]
    for x in range(w):
        p.append(1)
    o.append(p)
for a in A:
    if a[2]==1:
        for y in range(h):
            for x in range(a[0]):
                o[y][x]=0
    if a[2]==2:
        for y in range(h):
            for x in range(a[0],w):
                o[y][x]=0
    if a[2]==3:
        for y in range(a[1]):
            for x in range(w):
                o[y][x]=0
    if a[2]==4:
        for y in range(a[1],h):
            for x in range(w):
                o[y][x]=0
print(sum(map(sum,o)))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x_l, x_r, y_l, y_r = 0, W, 0, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x_l = max(x_l, x)
    elif a == 2:
        x_r = min(x_r, x)
    elif a ==3:
        y_l = max(y_l, y)
    else:
        y_r = min(y_r, y)
if x_l >= x_r or y_l >= y_r:
    print(0)
    exit()
print((x_r-x_l)*(y_r-y_l))

Submission status: Accepted

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

x_min, y_min = (0, 0)
x_max, y_max = (W, H)

for _ in range(N):
    if lst_xya[-1][2] == 4:
        if y_max > lst_xya[-1][1]:
            y_max = lst_xya[-1][1]
        lst_xya.pop()
    elif lst_xya[-1][2] == 3:
        if y_min < lst_xya[-1][1]:
            y_min = lst_xya[-1][1]
        lst_xya.pop()
    elif lst_xya[-1][2] == 2:
        if x_max > lst_xya[-1][0]:
            x_max = lst_xya[-1][0]
        lst_xya.pop()
    else:
        if x_min < lst_xya[-1][0]:
            x_min = lst_xya[-1][0]
        lst_xya.pop()
        
S = (x_max - x_min) * (y_max - y_min)
if x_max - x_min < 0 and y_max - y_min < 0:
    print(0)
else:
    print(S if S > 0 else 0)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xyaList = [list(map(int, input().split())) for _ in range(n)]
blackRec = [[0, w], [0, h]]
for i in range(n):
    x = xyaList[i][0]
    y = xyaList[i][1]
    a = xyaList[i][2]
    if a == 1 and blackRec[0][0] < x:
        blackRec[0][0] = x
    elif a == 2 and blackRec[0][1] > x:
        blackRec[0][1] = x
    elif a == 3 and blackRec[1][0] < y:
        blackRec[1][0] = y
    elif a == 4 and blackRec[1][1] > y:
        blackRec[1][1] = y
width = blackRec[0][1] - blackRec[0][0]
height = blackRec[1][1] - blackRec[1][0]
ans = width * height
if width < 0 or height < 0:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
dots=[list(map(int,input().split())) for i in range(N)]
#print(dots)
w=[0,W]
h=[0,H]

for i in range(N):
    if dots[i][2]==1:
        if w[0]<dots[i][0]:
            w[0]=dots[i][0]
    elif dots[i][2]==2:
        if w[1]>dots[i][0]:
            w[1]=dots[i][0]
    elif dots[i][2]==3:
        if h[0]<dots[i][1]:
            h[0]=dots[i][1]
    else:
        if h[1]>dots[i][1]:
            h[1]=dots[i][1]

if ((w[1]-w[0])>0)and((h[1]-h[0])>0):
    print((w[1]-w[0])*(h[1]-h[0]))
else:
    print("0")

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
s = w * h
l = [0,0]
r = [w,h]

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        if l[0] < x:
            l[0] = x
    elif a == 2:
        if r[0] > x:
            r[0] = x
    elif a == 3:
        if l[1] < y:
            l[1] = y
    else:
        if r[1] > y:
            r[1] = y

tate = r[1] - l[1]
yoko = r[0] - l[0]

if l[0] < r[0] and l[1] < r[1]:
    print(tate * yoko)
else:
    print(0)

Submission status: Accepted

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

xyal = []
for _ in range(n):
    xyal.append(list(map(int, input().split())))

for xya in xyal:
    if xya[2] == 1:
        for y in range(h):
            for x in range(xya[0]):
                whl[y][x] = 1

    if xya[2] == 2:
        for y in range(h):
            if xya[0]+1 > w:
                break
            for x in range(xya[0], w):
                whl[y][x] = 1

    if xya[2] == 3:
        for y in range(xya[1]):
            for x in range(w):
                whl[y][x] = 1

    if xya[2] == 4:
        for y in range(xya[1], h):
            for x in range(w):
                whl[y][x] = 1

ans = 0
for wh in whl:
    ans += wh.count(0)
print(ans)

Submission status: Accepted

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


# x, y軸を作る
w = [1] * (W)
h = [1] * (H)

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

ans = sum(w) * sum(h)
print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
b=c=0
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:b=max(b,x)
    if a==2:w=min(w,x)
    if a==3:c=max(c,y)
    if a==4:h=min(h,y)
print(max(0,(w-b))*max(0,(h-c)))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
X = [0, W]
Y = [0, H]
for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1 and X[0] < x:
    X[0] = x
  elif a == 2 and X[1] > x:
    X[1] = x
  elif a == 3 and Y[0] < y:
    Y[0] = y
  elif a == 4 and Y[1] > y:
    Y[1] = y

h = Y[1] - Y[0]
w = X[1] - X[0]
print(0 if h < 0 or w < 0 else h * w)

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
a,b,c,d = 0,0,w,h
for _ in range(n):
    x,y,i = map(int, input().split())
    if i == 1:
        a = max(a,x)
    elif i == 2:
        c = min(c,x)
    elif i == 3:
        b = max(b,y)
    elif i == 4:
        d = min(d,y)

print(max(0,c-a) * max(0,d-b))
# print(a,b,c,d)

Submission status: Accepted

Solution code:
W, H, N = [int(x) for x in input().split()]
H_lst = []
for i in range(H):
    W_lst = []
    for j in range(W):
        W_lst.append(0)
    H_lst.append(W_lst)
for n in range(N):
    x, y, a = [int(x) for x in input().split()]
    if a == 1:
        for i in range(H):
            for j in range(x):
                H_lst[i][j] = 1
    elif a == 2:
        for i in range(H):
            for j in range(x, W):
                H_lst[i][j] = 1
    elif a == 3:
        for i in range(y):
            for j in range(W):
                H_lst[i][j] = 1
    elif a == 4:
        for i in range(y, H):
            for j in range(W):
                H_lst[i][j] = 1
s = 0
for i in range(H):
    for j in range(W):
        if H_lst[i][j] == 0:
            s += 1
print(s)

Submission status: Accepted

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

x1, x2, y1, y2 = 0, W, 0, H

for xya in XYA:
    a = xya[2]
    if a == 1:
        x1 = max(x1, xya[0])
    if a == 2:
        x2 = min(x2, xya[0])
    if a == 3:
        y1 = max(y1, xya[1])
    if a == 4:
        y2 = min(y2, xya[1])

w = max(0, x2-x1)
h = max(0, y2-y1)

print(w*h)

Submission status: Accepted

Solution code:
# 入力 : Nセットの3個の数字
W, H, N = map(int, input().split())
list = [0 for i in range(0,N)]
for i in range(0,N) :
    x, y, a = map(int, input().split())
    list[i] = (x,y,a)

x_low = 0
x_high = W
y_low = 0
y_high = H

for i in range(0,N) :
    if list[i][2] == 1 :
        x_low = max(x_low, list[i][0])
    elif list[i][2] == 2 :
        x_high = min(x_high, list[i][0])
    elif list[i][2] == 3 :
        y_low = max(y_low, list[i][1])
    else :
        y_high = min(y_high, list[i][1])

area = (x_high - x_low) * (y_high - y_low)

if x_high < x_low or y_high < y_low :
    print(0)
else :
    print(area)

Submission status: Accepted

Solution code:
x, y, n = map(int, input().split())
wlist = []
for i in range(n):
    wlist.append(list(map(int, input().split())))
dst = []
x = [0, x]
y = [0, y]
for i in wlist:
    if i[2] == 1:
        x[0] = i[0] if i[0] > x[0] else x[0]
    elif i[2] == 2:
        x[1] = i[0] if i[0] < x[1] else x[1]
    elif i[2] == 3:
        y[0] = i[1] if i[1] > y[0] else y[0]
    else:
        y[1] = i[1] if i[1] < y[1] else y[1]
x = x[1]-x[0] if x[1]-x[0] > 0 else 0
y = y[1]-y[0] if y[1]-y[0] > 0 else 0
dst = x*y
print(dst)

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
min_x = 0
min_y = 0
max_x = w
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)
  elif a == 4:
    max_y = min(max_y, y)
print(max(0, max_x - min_x) * max(0, max_y-min_y))

Submission status: Accepted

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

Submission status: Accepted

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

Xend = W
Yend = H
Xstart = 0
Ystart = 0
for xya in XYA:
    if xya[2] == 1:
        Xstart = max(Xstart,xya[0])
    elif xya[2] == 2:
        Xend = min(Xend,xya[0])
    elif xya[2] == 3:
        Ystart = max(Ystart,xya[1])
    elif xya[2] == 4:
        Yend = min(Yend,xya[1])
if (Xend - Xstart)>0 and (Yend - Ystart)>0:
    print((Xend - Xstart)*(Yend - Ystart))
else:
    print(0)

Submission status: Accepted

Solution code:
x,y,n=list(map(int,input().split()))
xx=x
yy=y
S=[]
a1=0
b1=0
for _ in range(n):
    S.append(list(map(int,input().split())))
for a in S :
    if a[2]==1:
        a1 = max(a1,a[0])
    elif a[2]==2:
        xx = min(xx,a[0])
    elif a[2]==3:
        b1 = max(b1,a[1])
    elif a[2]==4:
        yy = min(yy,a[1])
print( (xx-a1)*(yy-b1) if a1<xx and b1<yy else 0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np


def main():
    W, H, N = map(int, input().split())
    result = np.zeros((W, H))

    for _ in range(N):
        X, Y, A = map(int, input().split())
        if A == 1:
            result[:X, :] = 1
        elif A == 2:
            result[X:, :] = 1
        elif A == 3:
            result[:, :Y] = 1
        elif A == 4:
            result[:, Y:] = 1
    print(np.count_nonzero(1 - result))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xlist = [0, w]
ylist = [0, h]
for count in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and xlist[0] < x: xlist[0] = x
    elif a == 2 and xlist[1] > x: xlist[1] = x
    elif a == 3 and ylist[0] < y: ylist[0] = y
    elif a == 4 and ylist[1] > y: ylist[1] = y
print(max(0, xlist[1] - xlist[0]) * max(0, ylist[1] - ylist[0]))

Submission status: Accepted

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

for i in range(len(xya)):
    if 1<=xya[i][2]<=2:
        for j in range(1,3):
            if xya[i][2]==j:
                lst[j-1].append(xya[i][0])
    else:
        for j in range(3,5):
            if xya[i][2]==j:
                lst[j-1].append(xya[i][1])

if min(lst[1])>=max(lst[0]):
    bla_width = w-min(lst[1])+max(lst[0])
else:
    bla_width = w

if min(lst[3])>=max(lst[2]):
    bla_height = h-min(lst[3])+max(lst[2])
else:
    bla_height = h

whi_area = (w-bla_width)*(h-bla_height)
print(whi_area)

Submission status: Accepted

Solution code:
W, H, N = list(map(int, input().split()))
W = [0, W]
H = [0, H]
pt = []
for i in range(N):
  x, y, n = list(map(int, input().split()))
  #for x, y, n in pt:
  if n == 1:
    if W[0] < x:
      W[0] = x
  elif n == 2:
    if x < W[1]:
      W[1] = x
  elif n == 3:
    if H[0] < y:
      H[0] = y
  else:
    if y < H[1]:
      H[1] = y
  #print("W", W, "H", H)
if W[0] < W[1] and H[0] < H[1]:
  print((W[1]-W[0])*(H[1]-H[0]))
else:
  print("0")

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for i in range(n)]
xya1=[i[0] for i in xya if i[2]==1]+[0]
xya2=[i[0] for i in xya if i[2]==2]+[w]
xya3=[i[1] for i in xya if i[2]==3]+[0]
xya4=[i[1] for i in xya if i[2]==4]+[h]
left=max(xya1)
right=min(xya2)
lower=max(xya3)
upper=min(xya4)
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())
XYA = [tuple(map(int, input().split())) for _ in range(N)]
XYA += [(0,0,1),(W,0,2),(0,0,3),(0,H,4)]
h1 = max(x for x,y,a in XYA if a == 1)
h2 = min(x for x,y,a in XYA if a == 2)
w1 = max(y for x,y,a in XYA if a == 3)
w2 = min(y for x,y,a in XYA if a == 4)
print((max(0,h2-h1))*(max(0,w2-w1)))

Submission status: Accepted

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

l = [list(map(int, input().split())) for i in range(N)]

coordinate = [[0, 0], [W, H]]

for i in l:
    if i[2] == 1:
        if coordinate[0][0] < i[0]:
            coordinate[0][0] = i[0]
    elif i[2] == 2:
        if coordinate[1][0] > i[0]:
            coordinate[1][0] = i[0]
    elif i[2] == 3:
        if coordinate[0][1] < i[1]:
            coordinate[0][1] = i[1]
    elif i[2] == 4:
        if coordinate[1][1] > i[1]:
            coordinate[1][1] = i[1]

x = coordinate[1][0] - coordinate[0][0]
y = coordinate[1][1] - coordinate[0][1]

if x <= 0 or y <= 0:
    print(0)
else:
    print(x * y)

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 2, Feb, 2020
"""

import sys
import itertools

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W, H, N = map(int, readline().split())
Xt = W
Xd = 0
Yt = H
Yd = 0
for _ in range(N):
    x, y, a = map(int, readline().split())
    if a == 1:
        Xd = max(x, Xd)
    elif a == 2:
        Xt = min(x, Xt)
    elif a == 3:
        Yd = max(y, Yd)
    else:
        Yt = min(y, Yt)

print(0 if Xd > Xt or Yd > Yt else (Xt - Xd) * (Yt - Yd))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys
import numpy as np

#n, a, b= map(int, input().split())
w, h, n  = map(int, input().split())
#s = list(str(input()))
#n = int(input())
#a = list(map(int, input().split()))

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

for i in range(n):
  if(a[i] == 1):
    area[:x[i],:] = 0
  if(a[i] == 2):
    area[x[i]:,:] = 0
  if(a[i] == 3):
    area[:,:y[i]] = 0
  if(a[i] == 4):
    area[:,y[i]:] = 0

print(np.count_nonzero(area == 1))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
up = h
down = 0
left = 0
right = w
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        left = max(left,x)
    elif a == 2:
        right = min(right,x)
    elif a == 3:
        down = max(down,y)
    else:
        up = min(up,y)
print(max(0, right - left) * max(0, up - down))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#x,y,a
#辺をどんどん更新していく
low_x=0
low_y=0
for i in range(n):
    if l[i][-1]==1 and low_x<l[i][0]:
        low_x=l[i][0]
    elif l[i][-1]==2 and w>l[i][0]:
        w=l[i][0]
    elif l[i][-1]==3 and low_y<l[i][1]:
        low_y=l[i][1]
    elif l[i][-1]==4 and h>l[i][1]:
        h=l[i][1]

#print(w,low_x,h,low_y)
print((w-low_x)*(h-low_y) if w>=low_x and h>=low_y else 0)

Submission status: Accepted

Solution code:
# input
W, H, N = map(int, input().split())
x, y, a = [0]*N, [0]*N, [0]*N
for i in range(N):
    tmp_x, tmp_y, tmp_a = map(int, input().split())
    x[i], y[i], a[i] = tmp_x, tmp_y, tmp_a
xya = zip(x,y,a)

W_L, W_R, W_H0, W_H1 = 0, W, 0, H
for x_i, y_i, a_i in xya:
    if a_i == 1:
        W_L = max(W_L,x_i)
    if a_i == 2:
        W_R = min(W_R,x_i)
    if a_i == 3:
        W_H0 = max(W_H0,y_i)
    if a_i == 4:
        W_H1 = min(W_H1,y_i)

if W_R-W_L <= 0 or W_H1-W_H0 <= 0:
    print(0)
else:
    print(abs(W_R-W_L)*abs(W_H1-W_H0))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
lx, rx, uy, dy = 0, W, H, 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        lx = max(lx, x)
    if a == 2:
        rx = min(rx, x)
    if a == 3:
        dy = max(dy, y)
    if a == 4:
        uy = min(uy, y)
# print(lx, rx, uy, dy)
print(max(0, uy - dy) * max(0, rx - lx))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
w,h,n = map(int,input().split())
# １行ですでにai がわかっているから逐次的に処理していけば良い。
min_x,min_y = w,h
max_x,max_y = 0,0
for i in range(n):
    x,y,a = map(int,input().split())
    #print(x,y,a)
    if a == 1: max_x = max(max_x,x)
    if a == 2: min_x = min(min_x,x)
    if a == 3: max_y = max(max_y,y)
    if a == 4: min_y = min(min_y,y)
#print(max_x,max_y,min_x,min_y)
print(max(0,min_x - max_x) * max(0,min_y - max_y))

Submission status: Accepted

Solution code:
import numpy as np
w,h,n=map(int,input().split())
ans=np.ones((h,w),dtype=np.int)
for _ in range(n):
    x,y,a=map(int,input().split())
    if a == 1:
        ans[:,:x]=0
    elif a == 2:
        ans[:,x:]=0
    elif a ==3:
        ans[:y,:]=0
    else:
        ans[y:,:]=0
print(np.count_nonzero(ans))

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
x_min, x_max = 0, w
y_min, y_max = 0, h
for _ in range(n):
    x,y,a = map(int, input().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)
    elif a == 4:
        y_max = min(y_max, y)
dx = x_max - x_min
dy = y_max - y_min
white_space = max(dx,0) * max(dy,0)
print(white_space)