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 = input().split()
lx ,ly ,hx ,hy = 0, 0, int(w), int(h)
for i in range(int(n)):
    S = list(map(int, input().split()))
    if S[2]==1 and lx<S[0]:
        lx = S[0]
    elif S[2]==2 and hx>S[0]:
        hx = S[0]
    elif S[2]==3 and ly<S[1]:
        ly = S[1]
    elif S[2]==4 and hy>S[1]:
        hy = S[1]
ans = int(hx-lx)*int(hy-ly) 
if hx-lx<=0 or hy-ly<=0:
    print(0)
else: print(ans)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
top,bottom,left,right = H,0,0,W

for x,y,a in src:
    if a == 1:
        left = max(left,x)
    elif a == 2:
        right = min(right,x)
    elif a == 3:
        bottom = max(bottom,y)
    else:
        top = min(top,y)
w = max(0, right-left)
h = max(0, top-bottom)
print(w*h)

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    w, h, n = list(map(int, input().split()))
    w_min, w_max = 0, w
    h_min, h_max = 0, h

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

        if a == 1:
            w_min = max(x, w_min)
        elif a == 2:
            w_max = min(x, w_max)
        elif a == 3:
            h_min = max(y, h_min)
        elif a == 4:
            h_max = min(y, h_max)

    print(max(w_max - w_min, 0) * max(h_max - h_min, 0))

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    w, h, n = list(map(int, input().split()))
    xya = [list(map(int, input().split())) for _ in range(n)]
    w_min = 0
    w_max = w
    h_min = 0
    h_max = h

    for x, y, a in xya:
        if (a == 1) and (x > w_min):
            w_min = x
        elif (a == 2) and (x < w_max):
            w_max = x
        elif (a == 3) and (y > h_min):
            h_min = y
        elif (a == 4) and (y < h_max):
            h_max = y

    print(max(w_max - w_min, 0) * max(h_max - h_min, 0))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
p, q = 0, 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        p = max(x, p)
    elif a == 2:
        w = min(x, w)
    elif a == 3:
        q = max(y, q)
    else:
        h = min(y, h)

if w - p >= 0 and h - q >= 0:
    print((w - p) * (h - q))
else:
    print(0)

Submission status: Accepted

Solution code:
def main():
    w, h, n = map(int, input().split())
    
    w_min, w_max = [0], [w]
    h_min, h_max = [0], [h]
    
    for i in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            w_min.append(x)
        elif a == 2:
            w_max.append(x)
        elif a == 3:
            h_min.append(y)
        else:
            h_max.append(y)
            
    w = min(w_max) - max(w_min)
    h = min(h_max) - max(h_min)
    
    if w > 0 and h > 0:
        print(w*h)
    else:
        print(0)

        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
t=[[int(i) for i in input().split()]for i in range(n)]
x_1,x_2,y_1,y_2=0,w,0,h
for i in range(n):
    if t[i][2]==1:
        ans=t[i][0]
        x_1=max(ans,x_1)
    elif t[i][2]==2:
        ans_2=t[i][0]
        x_2=min(ans_2,x_2)
    elif t[i][2]==3:
        ans_3=t[i][1]
        y_1=max(ans_3,y_1)
    elif t[i][2]==4:
        ans_4=t[i][1]
        y_2=min(ans_4,y_2)
if x_1<x_2 and y_1<y_2:
    print(abs(x_2-x_1)*abs(y_2-y_1))
else:
    print(0)

Submission status: Accepted

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

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

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = min(y, y_max)
print(max(y_max - y_min, 0) * max(x_max - x_min, 0))

Submission status: Accepted

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

l,r,t,b = [0],[W],[H],[0]

for i in range(N):
    x,y,a = map(int,input().split())
    if a==1: l.append(x)
    elif a==2: r.append(x)
    elif a==3: b.append(y)
    elif a==4: t.append(y)
        
W = min(r)-max(l) if min(r)-max(l)>=0 else 0
H = min(t)-max(b) if min(t)-max(b)>=0 else 0
        
print(W*H)

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
D = [list(map(int,input().split())) for k in range(N)]
mx = 0
my = 0
MX = W
MY = H
for d in D:
    if d[2] == 1:
        mx = max(mx,d[0])
    elif d[2] == 2:
        MX = min(MX,d[0])
    elif d[2] == 3:
        my = max(my,d[1])
    else:
        MY = min(MY,d[1])

if MX <= mx or MY <= my:
    print(0)
else:
    print((MX-mx)*(MY-my))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split());b=d=0
for _ in[0]*n:
    x,y,a=map(int,input().split())
    if a<2:b=max(x,b)
    elif a<3:w=min(x,w)
    elif a<4:d=max(y,d)
    else:h=min(h,y)
print([(w-b)*(h-d),0][(w<b)|(h<d)])

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split(' '))
minx = 0
maxx = W
miny = 0
maxy = H
for i in range(N):
    x, y, a = map(int, input().split(' '))
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        maxy = min(maxy, y)
if minx <= maxx and miny <= maxy:
    print((maxx-minx) * (maxy-miny))
else:
    print(0)

Submission status: Accepted

Solution code:
import numpy as np
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(n)]
x,y,a=[],[],[]
for z in xya:
    x.append(z[0])
    y.append(z[1])
    a.append(z[2])
pp = np.array([[1]*w]*h)
for i in range(n):
    if a[i]==1:
        pp[:, :x[i]]=0
    if a[i]==2:
        pp[:, x[i]:]=0
    if a[i]==3:
        pp[(h-y[i]):, :]=0
    if a[i]==4:
        pp[:(h-y[i]), :]=0
print(sum(sum(pp)))

Submission status: Accepted

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

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

for _ in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        left.append(x)
    elif a == 2:
        right.append(x)
    elif a == 3:
        down.append(y)
    elif a == 4:
        up.append(y)
        
if min(right) - max(left) <= 0 or min(up) - max(down) <= 0:
    print(0)
else:
    print((min(right) - max(left)) * (min(up) - max(down)))

Submission status: Accepted

Solution code:
def inpl(): return map(int, input().split())
W, H, N = inpl()
a = [0, W, 0, H]
for i in range(N):
    x, y, a_i = inpl()
    if a_i == 1:
        a[0] = max(a[0], x)
    elif a_i == 2:
        a[1] = min(a[1], x)
    elif a_i == 3:
        a[2] = max(a[2], y)
    else:
        a[3] = min(a[3], y)

if a[0]<a[1] and a[2]<a[3]:
    print((a[1]-a[0])*(a[3]-a[2]))
else:
    print(0)

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:
        X1 = max(x,X1)
    elif a == 2:
        X2 = min(x,X2)
    elif a == 3:
        Y1 = max(y,Y1)
    elif a == 4:
        Y2 = min(y,Y2)
print(max(0,(X2-X1))*max(0,(Y2-Y1)))

Submission status: Accepted

Solution code:
a, b, n = list(map(int,input().split()))

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

aa =0
ab =a
ac =0
ad =b

for i in range(n):
    if c[i][2] == 1:
        aa = max(aa,c[i][0])
    elif c[i][2] == 2:
        ab = min(ab,c[i][0])
    elif c[i][2] == 3:
        ac = max(ac,c[i][1])
    else:
        ad = min(ad,c[i][1])

if ab-aa > 0 and ad-ac > 0:
    print((ab-aa)*(ad-ac))
else:
    print(0)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
l = [[int(i) for i in input().split()] for i in range(n)]
start,end = [0,0],[w,h]

for i in range(n):
    if l[i][2]==1 and start[0]<l[i][0]:
        start[0] = l[i][0]
    elif l[i][2]==2 and end[0]>l[i][0]:
        end[0] = l[i][0]
    elif l[i][2]==3 and start[1]<l[i][1]:
        start[1] = l[i][1]
    elif l[i][2]==4 and end[1]>l[i][1]:
        end[1] = l[i][1]

ans = (end[0]-start[0])*(end[1]-start[1]) if start[0]<end[0] or start[1]<end[1] else -1
print(ans if ans > 0 else 0)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
t=[tuple(map(int,input().split()))for i in range(n)]
A=C=0
B=w
D=h
for i in range(n):
    if t[i][2]==1:
        A=max(A,t[i][0])
    elif t[i][2]==2:
        B=min(B,t[i][0])
    elif t[i][2]==3:
        C=max(C,t[i][1])
    elif t[i][2]==4:
        D=min(D,t[i][1])
n_h=D-C
n_w=B-A
if n_h<=0 or n_w<=0:
    print(0)
else:
    print(n_h*n_w)

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())
x_min = 0
y_min = 0
x_max = W
y_max = H
for i in range(N):
    if a[i] == 1:
        x_min = max(x_min,x[i])
    if a[i] == 2:
        x_max = min(x_max,x[i])
    if a[i] == 3:
        y_min = max(y_min,y[i])
    if a[i] == 4:
        y_max = min(y_max,y[i])
#print(x_min,x_max,y_min,y_max)
x_sub = max(x_max-x_min,0)
y_sub = max(y_max-y_min,0)
print(x_sub*y_sub)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
w, h, n = map(int, input().split())
xy = np.zeros((w,h))
xya = [[int(a) for a in input().split()] for _ in range(n)]
for i in range(n):
    if xya[i][2]==1:
        for x in range(xya[i][0]):
            xy[x][:h] = 1
    elif xya[i][2] == 2:
        for x in range(xya[i][0], w):
            xy[x][:h] = 1
    elif xya[i][2]==3:
        for x in range(w):
            for y in range(xya[i][1]):
                xy[x][y] = 1
    elif xya[i][2] == 4:
        for x in range(w):
            for y in range(xya[i][1], h):
                xy[x][y] = 1
wh = [int(item) for wh in xy for item in wh]
print(wh.count(0))

Submission status: Accepted

Solution code:
w, h ,n = map(int, input().split())
sq = list(list(True for _ in range(h)) for _ in range(w))##sq[w][h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for ix in range(x):
            for iy in range(h):
                sq[ix][iy] = False
    if a == 2:
        for ix in range(x, w):
            for iy in range(h):
                sq[ix][iy] = False
    if a == 3:
        for ix in range(w):
            for iy in range(y):
                sq[ix][iy] = False
    if a == 4:
        for ix in range(w):
            for iy in range(y, h):
                sq[ix][iy] = False
s = 0
for h in range(w):
    s += sq[h].count(True)
print(s)

Submission status: Accepted

Solution code:
import numpy as np
W, H, N = map(int, input().split())
x = []
y = []
a = []
for _ in range(N):
    b, c, d = map(int, input().split())
    x.append(b)
    y.append(c)
    a.append(d)
A = np.zeros((H, W))

for i in range(N):
    if a[i] == 1:
        for j in range(x[i]):
            for k in range(H):
                A[k][j] = 1
    elif a[i] == 2:
        for j in range(x[i],W):
            for k in range(H):
                A[k][j] = 1
    elif a[i] == 3:
        for j in range(y[i]):
            for k in range(W):
                A[j][k] = 1
    elif a[i] == 4:
        for j in range(y[i], H):
            for k in range(W):
                A[j][k] = 1

print(np.sum(A==0))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
a=[0 for i in range(N)]
for i in range(N):
    x[i],y[i],a[i]=map(int,input().split())
C=[[0 for i in range(W)] for j in range(H)]
for k in range(N):
    if a[k]==1:
        for i in range(H):
            for j in range(x[k]):
                C[i][j]=1
    elif a[k]==2:
        for i in range(H):
            for j in range(x[k],W):
                C[i][j]=1
    elif a[k]==3:
        for i in range(y[k]):
            for j in range(W):
                C[i][j]=1
    else:
        for i in range(y[k],H):
            for j in range(W):
                C[i][j]=1
Ans=0
for i in range(H):
    for j in range(W):
        if C[i][j]==0:
            Ans+=1
print(Ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def area(x2, y2, points):
    x1 = y1 = 0
    for x, y, a in points:
        if a == 1:
            x1 = min(max(x1, x), x2)
        elif a == 2:
            x2 = max(min(x2, x), x1)
        elif a == 3:
            y1 = min(max(y1, y), y2)
        else:
            y2 = max(min(y2, y), y1)
    return (x2 - x1) * (y2 - y1)


if __name__ == '__main__':
    w, h, n = list(map(int, input().split()))
    points = [list(map(int, input().split())) for _ in range(n)]
    print(area(w, h, points))

Submission status: Accepted

Solution code:
def init_rectangle(w, h):
    rectangle = []
    for x in range(w):
        x_list = []
        for y in range(h):
            x_list.append(True)
        rectangle.append(x_list)
    return rectangle

def area(rectangle):
    count = 0
    for i in rectangle:
        for j in i:
            if j:
                count += 1
    return count

def paint_point(rectangle, w, h, x1, x2, y1, y2):
    for x in range(x1, x2):
        for y in range(h):
            rectangle[x][y] = False
    for x in range(w):
        for y in range(y1, y2):
            rectangle[x][y] = False
        
def paint(rectangle, w, h, points):
    for x, y, a in points:
        x1 = x2 = y1 = y2 = 0
        if a == 1:
            x2 = x
        elif a == 2:
            x1 = x
            x2 = w
        elif a == 3:
            y2 = y
        else:
            y1 = y
            y2 = h
        paint_point(rectangle, w, h, x1, x2, y1, y2)


if __name__ == '__main__':
    w, h, n = list(map(int, input().split()))
    points = [list(map(int, input().split())) for _ in range(n)]
    rectangle = init_rectangle(w, h)
    paint(rectangle, w, h, points)
    print(area(rectangle))

Submission status: Accepted

Solution code:
w, h, n = [int(x) for x in input().split()]
xm, xM, ym, yM = 0, w, 0, h
for _ in range(n):
	x, y, a = [int(x) for x in input().split()]
	if a == 1: xm = max(xm, x)
	elif a == 2: xM = min(xM, x)
	elif a == 3: ym = max(ym, y)
	else: yM = min(yM, y)
if yM > ym and xM > xm: print((xM - xm) * (yM - ym))
else: print(0)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
top = H
right = W
left = 0
bot = 0
for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1 and left < x:
    left = min(x,right)
  elif a == 2 and x < right:
    right = max(x,left)
  elif a == 3 and bot < y:
    bot = min(y,top)
  elif a == 4 and y < top:
    top = max(y,bot)
print((right - left)*(top - bot))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
lis1 = [0]
lis2 = [w]
lis3 = [0]
lis4 = [h]
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:lis1.append(x)
    if a == 2:lis2.append(x)
    if a == 3:lis3.append(y)
    if a == 4:lis4.append(y)
cou1 = max(lis1)
cou2 = min(lis2)
cou3 = max(lis3)
cou4 = min(lis4)

if cou1 + (w -cou2) >= w or cou3 + (h - cou4) >= h:
    print("0")
else:
    print((w-(cou1 + (w - cou2))) * ((h-(cou3 + (h - cou4)))))

Submission status: Accepted

Solution code:
x_r, y_o, N = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
x_l = 0
y_u = 0
area = x_r * y_o
if area == 0:
    print(area)
else:
    for i in a:
        if i[2] == 1:
            if i[0] <= x_l:
                continue
            else:
                area -= (i[0] - x_l) * (y_o - y_u)
                if i[0] >= x_r:
                    area = 0
                    break
                else:
                    x_l = i[0]
        elif i[2] == 2:
            if i[0] >= x_r:
                continue
            else:
                area -= (x_r - i[0]) * (y_o - y_u)
                if i[0] <= x_l:
                    area = 0
                    break
                else:
                    x_r = i[0]
        elif i[2] == 3:
            if i[1] <= y_u:
                continue
            else:
                area -= (i[1] - y_u) * (x_r - x_l)
                if i[1] >= y_o:
                    area = 0
                    break
                else:
                    y_u = i[1]
        else:
            if i[1] >= y_o:
                continue
            else:
                area -= (y_o - i[1]) * (x_r - x_l)
                if i[1] <= y_u:
                    area = 0
                    break
                else:
                    y_o = i[1]
    print(area)

Submission status: Accepted

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

Submission status: Accepted

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

ma = [[0 for i in range(w)] for i in range(h)]


# a == 1 x < xi
# a == 2 x > xi
# a == 3 y < yi
# a == 4 y > yi

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w_r, h_u, n = map(int, input().split())
xya = []
for i in range(n): xya.append(list(map(int, input().split())))

w_l = 0
h_l = 0
for x in xya:
    if x[2] == 1:
        w_l = max(x[0], w_l)
    elif x[2] == 2:
        w_r = min(x[0], w_r)
    elif x[2] == 3:
        h_l = max(x[1], h_l)
    else:
        h_u = min(x[1], h_u)

print(max((max(w_r-w_l, 0))*max((h_u-h_l), 0), 0))

Submission status: Accepted

Solution code:
W,H,N=map(int, raw_input().split())
C=[]
for i in range(N):
	x,y,a=map(int, raw_input().split())
	C.append((x,y,a))

R=[[ 0 for i in range(H)] for j in range(W)]


for i in C:
	if i[2]==1:
		for x in range(i[0]):
			for y in range(H):
				R[x][y]=1
	elif i[2]==2:
		for x in range(i[0],W):
			for y in range(H):
				R[x][y]=1
	elif i[2]==3:
		for x in range(W):
			for y in range(i[1]):
				R[x][y]=1
	elif i[2]==4:
		for x in range(W):
			for y in range(i[1],H):
				R[x][y]=1


ans=0
for i in R:
	ans+=len(filter(lambda n:n==0, i) )

print ans

Submission status: Accepted

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

    #f1(W, H, N, xya)
    f2(W, H, N, xya)


def f1(W, H, N, xya):
    rect = [[1] * W for _ in range(H)]

    for x, y, a in xya:
        x_range = range(W)
        y_range = range(H)
        if a == 1:
            x_range = range(x)
        elif a == 2:
            x_range = range(x, W)
        elif a == 3:
            y_range = range(y)
        elif a == 4:
            y_range = range(y, H)

        for i in y_range:
            for j in x_range:
                rect[i][j] = 0

    ans = sum(map(sum, rect))
    print(ans)


def f2(W, H, N, xya):
    x1, y1 = 0, 0
    x2, y2 = W, H

    for x, y, a in xya:
        if a == 1:
            x1 = max(x, x1)
        elif a == 2:
            x2 = min(x, x2)
        elif a == 3:
            y1 = max(y, y1)
        elif a == 4:
            y2 = min(y, y2)

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

    #print((x1, y1), (x2, y2))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
W,H,N=map(int, input().split())
 
X=[]
Y=[]
A=[]
for i in range(N):
    x,y,a=map(int, input().split())
    X.append(x)
    Y.append(y)
    A.append(a)
 
T=W*H
Ws=0
Hs=0
Wh=W
Hh=H
for i in range(N):
    if A[i]==1:
        if X[i]-Ws>=0:
            T-=(X[i]-Ws)*(Hh-Hs)
            Ws=X[i]
    elif A[i]==2:
        if Wh-X[i]>=0:
            T-=(Wh-X[i])*(Hh-Hs)
            Wh=X[i]
    elif A[i]==3:
        if Y[i]-Hs>=0:
            T-=(Y[i]-Hs)*(Wh-Ws)
            Hs=Y[i]
    elif A[i]==4:
        if Hh-Y[i]>=0:
            T-=(Hh-Y[i])*(Wh-Ws)
            Hh=Y[i]
    if T<=0:
        T=0
        break
 
print(T)

Submission status: Accepted

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

X=[]
Y=[]
A=[]
for i in range(N):
    x,y,a=map(int, input().split())
    X.append(x)
    Y.append(y)
    A.append(a)

T=W*H
Ws=0
Hs=0
Wh=W
Hh=H
for i in range(N):
    if A[i]==1:
        if X[i]-Ws>=0:
            T-=(X[i]-Ws)*(Hh-Hs)
            Ws=X[i]
    elif A[i]==2:
        if Wh-X[i]>=0:
            T-=(Wh-X[i])*(Hh-Hs)
            Wh=X[i]
    elif A[i]==3:
        if Y[i]-Hs>=0:
            T-=(Y[i]-Hs)*(Wh-Ws)
            Hs=Y[i]
    elif A[i]==4:
        if Hh-Y[i]>=0:
            T-=(Hh-Y[i])*(Wh-Ws)
            Hh=Y[i]
    if T<=0:
        T=0
        break

print(T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
table = [[1]*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):
                table[i][j] = 0
    if a == 2:
        for i in range(x,w):
            for j in range(h):
                table[i][j] = 0
    if a == 3:
        for i in range(w):
            for j in range(y):
                table[i][j] = 0
    if a == 4:
        for i in range(w):
            for j in range(y,h):
                table[i][j] = 0
print(sum(map(sum,table)))

Submission status: Accepted

Solution code:
W, H, N = map(int,input().split())
points = [list(map(int,input().split())) for _ in range(N)]
width = list(range(1, W + 2))
height = list(range(1, H + 2))

a = len(width)
b = len(height)

for i in range(N):
    if points[i][2] == 1:
        for j in range(a):
            if width[j] < points[i][0] + 1:
                width[j] = 0
    if points[i][2] == 2:
        for j in range(a):
            if width[j] > points[i][0] + 1:
                width[j] = 0
    if points[i][2] == 3:
        for j in range(b):
            if height[j] < points[i][1] + 1:
                height[j] = 0
    if points[i][2] == 4:
        for j in range(b):
            if height[j] > points[i][1] + 1:
                height[j] = 0

c = width.count(0)
d = height.count(0)

for i in range(c):
    width.remove(0)
for i in range(d):
    height.remove(0)
if width != []:
    s = max(width)
    t = min(width)
else:
    s, t = 0, 0
if height != []:
    x = max(height)
    y = min(height)
else:
    x, y = 0, 0
ans = (s-t) * (x-y)
print(ans)

Submission status: Accepted

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

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

for i in range(n):
   x, y, a = map(int, input().split())
   if a == 1:
      xmin = max(xmin, x)
   elif a == 2:
      xmax = min(xmax, x)
   elif a == 3:
      ymin = max(ymin, y)
   elif a == 4:
      ymax = min(ymax, y)

xmax = max(xmin, xmax)
ymax = max(ymin, ymax)

print((xmax-xmin)*(ymax-ymin))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

W, H, N = map(int, input().split())
XYA = [tuple(map(int, input().split())) for i in range(N)]
Field = [[1]*W for i in range(H)]
Field = np.array(Field)

for x, y, a in XYA:
    if a == 1:
        Field[:, :x] = 0
    if a == 2:
        Field[:, x:] = 0
    if a == 3:
        Field[:y, :] = 0
    if a == 4:
        Field[y:, :] = 0

ans = Field.sum()
print(ans)

Submission status: Accepted

Solution code:


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

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

for _ 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)

x2 = max(x1, x2)
y2 = max(y1, y2)

print((y2 - y1) * (x2 - x1))

Submission status: Accepted

Solution code:
def LI(): return [int(x) for x in input().split(" ")]
def LS(): return [str(x) for x in input().split(" ")]
def ItoS(L): return [str(x) for x in L]
def StoI(L): return [int(c) for c in L]


def solve():
    w, h, n = LI()
    X, Y, A = [], [], []
    for _ in range(n):
        tmp1, tmp2, tmp3 = LI()
        X.append(tmp1)
        Y.append(tmp2)
        A.append(tmp3)

    field = [[1 for _ in range(w)] for __ in range(h)]

    for i, a in enumerate(A):
        if a == 1:
            for j in range(X[i]):
                for k in range(h):
                    field[k][j] = 0
        elif a == 2:
            for j in range(X[i], w):
                for k in range(h):
                    field[k][j] = 0
        elif a == 3:
            for j in range(Y[i]):
                for k in range(w):
                    field[j][k] = 0
        elif a == 4:
            for j in range(Y[i], h):
                for k in range(w):
                    field[j][k] = 0
        else:
            pass
        
    ans = 0
    for ele in field:
        ans += ele.count(1)

    print(ans)


solve()

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for _ in [0]*n]
minx = max([x for x,y,a in xya if a==1]+[0])
maxx = min([x for x,y,a in xya if a==2]+[w])
miny = max([y for x,y,a in xya if a==3]+[0])
maxy = min([y for x,y,a in xya if a==4]+[h])
print(max(0,maxx-minx)*max(0,maxy-miny))