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:
def paint(rect, x, y, a):
    if a == 1:
        indx = x
        for j in range(len(rect)):
            for i in range(indx):
                rect[j][i] = 1
    elif a == 2:
        indx = x
        for j in range(len(rect)):
            for i in range(indx, len(rect[0])):
                rect[j][i] = 1
    elif a == 3:
        indx = y
        for j in range(indx):
            for i in range(len(rect[0])):
                rect[j][i] = 1
    elif a == 4:
        indx = y
        for j in range(indx, len(rect)):
            for i in range(len(rect[0])):
                rect[j][i] = 1

def disp(rect):
    for i in range(len(rect)):
        print(rect[i])

def sum(rect):
    sum = 0
    for i in range(len(rect)):
        for j in range(len(rect[0])):
            sum += rect[i][j]
    return sum

if __name__ == '__main__':
    [W, H, N] = [int(i) for i in raw_input().split(' ')]
    rectangle = [[0 for i in range(W)] for j in range(H)]
    for i in range(N):
        [x, y, a] = [int(n) for n in raw_input().split(' ')]
        paint(rectangle, x, y, a)
    print(H*W - sum(rectangle))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    w, h, n = [int(x) for x in input().split()]
    dots = []
    x_start = 0
    y_start = 0
    x_finish = w
    y_finish = h
    zero_flag = False
    for _ in range(n):
        dots.append([int(x) for x in input().split()])
    for dot in dots:
        if dot[2] == 1:
            if dot[0] > x_start:
                x_start = dot[0]
        if dot[2] == 2:
            if dot[0] < x_finish:
                x_finish = dot[0]
        if dot[2] == 3:
            if dot[1] > y_start:
                y_start = dot[1]
        if dot[2] == 4:
            if dot[1] < y_finish:
                y_finish = dot[1]
        if x_finish <= x_start or y_finish <= y_start:
            zero_flag = True
            break

    if zero_flag:
        ans = 0
    else:
        ans = (x_finish - x_start) * (y_finish - y_start)
    print(ans)

Submission status: Accepted

Solution code:


w,h,n = map(int,raw_input().split())
l = []
for i in range(n):
    row = map(int,raw_input().split())
    l.append(row)

minX =  map(lambda i:i[0], filter(lambda i:i[2]==1,l))
minX.append(0)
minX = max(minX)

maxX =  map(lambda i:i[0], filter(lambda i:i[2]==2,l))
maxX.append(w)
maxX = min(maxX)

minY =  map(lambda i:i[1], filter(lambda i:i[2]==3,l))
minY.append(0)
minY = max(minY)

maxY =  map(lambda i:i[1], filter(lambda i:i[2]==4,l))
maxY.append(w)
maxY = min(maxY)

X = maxX-minX
Y = maxY-minY
if X>0 and Y>0:
    print X*Y
else:
    print 0

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
menseki = W*H
left_x = 0
right_x = W
top_y = H
bottom_y = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > left_x:
            left_x = x
    elif a == 2:
        if x < right_x:
            right_x = x
    elif a == 3:
        if y > bottom_y:
            bottom_y = y
    else:
        if y < top_y:
            top_y = y
ans = (right_x - left_x) * (top_y - bottom_y)
if right_x <= left_x or top_y <= bottom_y:
    ans = 0
print(ans)

Submission status: Accepted

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

min_x = 0
min_y = 0
max_x = W
max_y = H

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        min_x = max(min_x, x)
    if a == 2:
        max_x = min(max_x, x)
    if a == 3:
        min_y = max(min_y, y)
    if a == 4:
        max_y = min(max_y, y)

ans_W = max(0, (max_x - min_x))
ans_H = max(0, (max_y - min_y))

print(ans_W * ans_H)

Submission status: Accepted

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

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

for _ in range(N):
    xi, yi, ai = map(int, input().split())
    if ai == 1:
        left = max(left, xi)
    elif ai == 2:
        right = min(right, xi)
    elif ai == 3:
        top = max(top, yi)
    elif ai == 4:
        bottom = min(bottom, yi)

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
xl=0
xh=w
yl=0
yh=h
for _ in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        xl=max(xl,x)
    elif a==2:
        xh=min(xh,x)
    elif a==3:
        yl=max(yl,y)
    else:
        yh=min(yh,y)

if xl>=xh or yl>=yh:
    print(0)
else:
    print((xh-xl)*(yh-yl))

Submission status: Accepted

Solution code:
import sys
lines = sys.stdin.readlines()
sizes = lines[0].split(" ")
W=int(sizes[0])
H=int(sizes[1])
N=int(sizes[2])
#print (W,H,N)

calW = W
calH = H
maxX = 0
minX = W
maxY = 0
minY = H
for line in lines[1:]:
    inp = []
    for i in line.split(" "):
        inp.append(int(i))
    #print (inp)
    if inp[2]==1 and inp[0]>maxX:
        calW -= inp[0] - maxX
        maxX = inp[0]
    elif inp[2]==2 and inp[0]<minX:
        calW -= W-inp[0] - (W-minX)
        minX = inp[0]
    elif inp[2]==3 and inp[1]>maxY:
        calH -= inp[1] - maxY
        maxY = inp[1]
    elif inp[2]==4 and inp[1]<minY:
        calH -= H-inp[1] - (H-minY)
        minY = inp[1]
    #print (calW,calH)

if calW<0 or calH<0:
    print (0)
else:
    print (calW*calH)

Submission status: Accepted

Solution code:
sagyou = []
W,H,N = map(int,input().split(' '))
for i in range(0,N):
    sagyou.append(list(map(int,input().split(' '))))
area = [[0,W],[0,H]]
for i in range(0,N):
    if sagyou[i][2] == 1 and area[0][0] <= sagyou[i][0]:
        area[0][0] = sagyou[i][0]
    elif sagyou[i][2] == 2 and area[0][1] >= sagyou[i][0]:
        area[0][1] = sagyou[i][0]
    elif sagyou[i][2] == 3 and area[1][0] <= sagyou[i][1]:
        area[1][0] = sagyou[i][1]
    elif sagyou[i][2] == 4 and area[1][1] >= sagyou[i][1]:
        area[1][1] = sagyou[i][1]
    if (area[0][1]-area[0][0])*(area[1][1]-area[1][0]) <= 0:
        print(0)
        break
    if i == N-1 and (area[0][1]-area[0][0])*(area[1][1]-area[1][0]) >= 0:
        print((area[0][1]-area[0][0])*(area[1][1]-area[1][0]))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    whn = list(map(int,input().split()))
    
    a = [0, whn[0], 0, whn[1]]
    for n in range(whn[2]):
        t = list(map(int,input().split()))
        if t[2] == 1:
            a[0] = max(a[0], t[0])
        elif t[2] == 2:
            a[1] = min(a[1], t[0])
        elif t[2] == 3:
            a[2] = max(a[2], t[1])
        elif t[2] == 4:
            a[3] = min(a[3], t[1])
    if a[1] < a[0] or a[3] < a[2]:
        print(0)
    else:
        print((a[1]-a[0])*(a[3]-a[2]))

Submission status: Accepted

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

W=int(W)
H=int(H)
N=int(N)

wl=[0,W]
hl=[0,H]

for x in a:
	if x[2]==1:
		wl[0]=max(wl[0],x[0])
	elif x[2]==2:
		wl[1]=min(wl[1],x[0])
	elif x[2]==3:
		hl[0]=max(hl[0],x[1])
	elif x[2]==4:
		hl[1]=min(hl[1],x[1])

high=0
width=0
if wl[1]-wl[0]>0:
	width=wl[1]-wl[0]
if hl[1]-hl[0]>0:
	high=hl[1]-hl[0]
print(high*width)

Submission status: Accepted

Solution code:
W, H, N =  map(int, raw_input().split())
result = [0, W, 0, H]
for n in range(N):
    x, y, a =  map(int, raw_input().split())
    if a == 1:
        result[0] = max(result[0], x)
    if a == 2:
        result[1] = min(result[1], x)
    if a == 3:
        result[2] = max(result[2], y)
    if a == 4:
        result[3] = min(result[3], y)

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

Submission status: Accepted

Solution code:
# B
W, H, N = [int(i) for i in input().split()]
xya = [input().split() for i in range(N)]
ld, ru = [0, 0], [W, H]
for i in range(len(xya)):
    id = int(xya[i][2])
    if id == 1 or id == 3:
        ld[id//2] = max(ld[id//2], int(xya[i][id//2]))
    elif id == 2 or id == 4:
        ru[id//3] = min(ru[id//3], int(xya[i][id//3]))
        
if (ru[0]-ld[0]) > 0 and (ru[1]-ld[1])>0:
    print((ru[0]-ld[0])*(ru[1]-ld[1]))
else: print(0)

Submission status: Accepted

Solution code:
list = input().split()
w = int(list[0])
h = int(list[1])
n = int(list[2])
list2 = []
i = 0
while i < n:
   list2.append(input().split())
   i += 1

i = 0
a = int(0)
b = int(w)
c = int(0)
d = int(h)
while i < n:
    list3 = list2[i]
    if int(list3[2]) == 1:
        a = max(a,int(list3[0]))
    elif int(list3[2]) == 2:
        b = min(b,int(list3[0]))
    elif int(list3[2]) == 3:
        c = max(c,int(list3[1]))
    else:
        d = min(d,int(list3[1]))
    i += 1
if b < a:
    print(0)
elif d < c:
    print(0)
else:
    print((b-a)*(d-c))

Submission status: Accepted

Solution code:
w, h, n = map(int, raw_input().split())
a = []
for i in range(n):
    a.append(map(int, raw_input().split()))

minx = 0
miny = 0
maxx = w
maxy = h

for i in range(n):
    if a[i][2] == 1:
        minx = max(minx, a[i][0])
    elif a[i][2] == 2:
        maxx = min(maxx, a[i][0])
    elif a[i][2] == 3:
        miny = max(miny, a[i][1])
    elif a[i][2] == 4:
        maxy = min(maxy, a[i][1])

if maxy <= miny or maxx <= minx:
    print 0
else:
    print (maxy - miny) * (maxx - minx)

Submission status: Accepted

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

for i in range(N):
    x, y, a = map(int, input().split(' '))
    srange = range(W)
    trange = range(H)
    if a==1:
        srange = range(x)
    if a==2:
        srange = range(x, W)
    if a==3:
        trange = range(y)
    if a==4:
        trange = range(y, H)
    for t in trange:
        for s in srange:
            table[t][s] = 1

area = 0
for i in table:
    area += i.count(0)
print(area)

Submission status: Accepted

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

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

x1, x2, y3, y4 = 0, W, 0, H

for i in range(N):
	x, y, a = list(map( int, input().split()))
	if a == 1:
		if x > x1:
			x1 = x
	elif a == 2:
		if x < x2:
			x2 = x
	elif a == 3:
		if y > y3:
			y3 = y
	else:
		if y < y4:
			y4 = y

w = x2 - x1
h = y4 - y3

if w > 0 and h > 0:
	print(w * h)
else:
	print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

W, H, N = map(int, raw_input().split())
w = [0, W]
h = [0, H]

for i in xrange(N):
    x, y, a = map(int, raw_input().split())
    if a == 1 and w[0] < x:
        w[0] = x
    elif a == 2 and w[1] > x :
        w[1] = x
    elif a == 3 and h[0] < y:
        h[0] = y
    elif a == 4 and h[1] > y:
        h[1] = y

print max(w[1] - w[0], 0) * max(h[1] - h[0], 0)

Submission status: Accepted

Solution code:
dat = raw_input()
(W,H,N) = dat.split(" ")
W = int(W)
H = int(H)
N = int(N)

data = [[0 for y in range(H)] for x in range(W)]

for a in range(0,N):
  dat = raw_input()
  (x,y,a) = dat.split(" ")
  x = int(x)
  y = int(y)
  a = int(a)
  if a == 1:
    for a in range(0,x):
      for b in range(0,H):
        data[a][b] = 1
  elif a == 2:
    for a in range(x,W):
      for b in range(0,H):
        data[a][b] = 1
  elif a == 3:
    for a in range(0,W):
      for b in range(0,y):
        data[a][b] = 1
  elif a == 4:
    for a in range(0,W):
      for b in range(y,H):
        data[a][b] = 1
ans = 0
for x in data:
  ans += x.count(0)

print ans

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def main():
    w, h, n = [int(i) for i in raw_input().split()]
    x_min, x_max, y_min, y_max = 0, w, 0, h
    for _ in range(n):
        x, y, a = [int(i) for i in raw_input().split()]
        if a == 1:
            x_min = max(x_min, x)
        if a == 2:
            x_max = min(x_max, x)
        if a == 3:
            y_min = max(y_min, y)
        if a == 4:
            y_max = min(y_max, y)
    if x_min > x_max:
        print 0
    elif y_min > y_max:
        print 0
    else:
        print (x_max-x_min)*(y_max-y_min)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
minx = 0
miny = 0
maxx = w
maxy = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        minx = x if x > minx else minx
    elif a == 2:
        maxx = x if maxx > x else maxx
    elif a == 3:
        miny = y if y > miny else miny
    else:
        maxy = y if maxy > y else maxy
width = maxx-minx if maxx > minx else 0
height = maxy-miny if maxy > miny else 0
print(width*height)

Submission status: Accepted

Solution code:
w, h, n = map(int, raw_input().split())
x = [1 for i in range(w)]
y = [1 for i in range(h)]
for i in range(n):
    x1, y1, a = map(int, raw_input().split())
    if a == 1:
        for t in range(x1):
            x[t] = 0
    if a == 2:
        for t in range(x1, w):
            x[t] = 0
    if a == 3:
        for t in range(y1):
            y[t] = 0
    if a == 4:
        for t in range(y1, h):
            y[t] = 0
print sum(x)*sum(y)

Submission status: Accepted

Solution code:

w, h, n = list(map(lambda x: int(x), input().split()))

xr = [0]
xl = [w]
yu = [h]
yd = [0]

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

    if a == 1:
        xr.append(x)
    elif a == 2:
        xl.append(x)
    elif a == 3:
        yd.append(y)
    elif a == 4:
        yu.append(y)


x_1 = max(xr) or 0
x_2 = min(xl) or w
y_1 = max(yd) or 0
y_2 = min(yu) or h


ans = (x_2 - x_1) * (y_2 - y_1)

if ans < 0:
    ans = 0

print(ans)

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: Runtime Error

Solution code:
import numpy as np
W,H,N = map(int, input().split())
X = np.zeros((H,W))
print(X)
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-1)
    elif a == 2:
        x2 = min(x2,x-1)
    elif a == 3:#より下黒
        y1 = max(y1,y-1)
    else:
        y2 = max(y2,y-1)
X[:][::x1] = 1
X[x2:][:] = 1
print(X)
#X[y1:][:] = 1
X[y2:][:] = 1
print(X)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# 63 B - すぬけ君の塗り絵 2 イージー
W,H,N = map(int,input().split())

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

mtrx = [['.']*W for _ in range(H)]

for a,(x,y) in zip(A,zip(X,Y)):
    if a == 1:
        for i in range(H):
            for j in range(x+1):
                mtrx[i][j] = '#'
    if a == 2:
        for i in range(H):
            for j in range(x+1,W):
                mtrx[i][j] = '#'
    if a == 3:
        for i in range(y+1):
            mtrx[i] = ['#']*W
    if a == 4:
        for i in range(y+1,W):
            mtrx[i] = ['#']*W
ans = 0
for i in range(H):
    for j in range(W):
        if mtrx[i][j] == '.':
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
#prepare
L = []
Q = []

#input
W, H, N, = map(int,raw_input().split())
for i in range(N):
    L.append(map(int,raw_input().split()))
x1=0
x2=W
y1=0
y2=H

#calculate
Q = [row[2] for row in L]


for k in range(N):
    if Q[k] == 1:
        x1 = max(x1,L[k][0])
    elif Q[k] == 2:
        x2 = min(x2,L[k][0])
    elif Q[k] == 3:
        y1 = max(y1,L[k][1])
    elif Q[k] == 4:
        y2 = min(y2,L[k][1])

print(max(0,x2-x1) * max(0,y2-y1))

Submission status: Runtime Error

Solution code:
#prepare
L = []
Q = []

#input
W, H, N, = map(int,raw_input().split())
for i in range(N):
    L.append(map(int,raw_input().split()))
x1=0
x2=W
y1=0
y2=H

#calculate
Q = [row[2] for row in L]


for k in range(N):
    if Q[k] == 1:
        x1 = max(x1,L[k][0])
    elif Q[k] == 2:
        x2 = min(x2,L[k][0])
    elif Q[k] == 3:
        y1 = max(y1,L[k][1])
    elif Q[k] == 4:
        y2 = min(y2,L[k][1])

print max(0,x2-x1) * max(0,y2-y1)

Submission status: Runtime Error

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

l, r, b, t = 0, w, 0, h
for x, y, a in xya:
    if a == 1:
        l = max(x, l)
    elif a == 2:
        r = min(x, r)
    elif a == 3:
        b = max(y, b)
    elif a == 4:
        t = min(y, u)
print(max(0, r - l) * max(0, t - b))

Submission status: Runtime Error

Solution code:
#
# abc047 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5 4 2
2 1 1
3 3 4"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5 4 3
2 1 1
3 3 4
1 4 2"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3"""
        output = """64"""
        self.assertIO(input, output)


def resolve():
    W, H, N = map(int, input().split())
    a = []
    ox = 0
    oy = 0
    for _ in range(N):
        a.append(list(map(int, input().split())))
    for i in range(N):
        if a[i][2] == 1:
            ox = max(a[i][0], ox)
        elif a[i][2] == 2:
            W = min(a[i][0], W)
        elif a[i][2] == 3:
            oy = max(a[i][1], oy)
        elif a[i][2] == 4:
            H = min(a[i][1], H)
    print(max((W-ox))*max((H-oy), 0))


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

  if a==1:
    l[:,:x] = 1
    #print(l[:,x:])
  elif a==2:
    l[:,x:] = 1
  elif a==3:
    l[:y,:] = 1
  elif a==4:
    l[y:,:] = 1
print(H*W-int(l.sum()))

Submission status: Runtime Error

Solution code:
W,H,N=map(int,input().split())
List = []
for i in range (N):
  List.append(list(map(int, input().split())))
WRange = [0,W]
HRange = [0,H]
for i in range(N):
  if List[i][2] == 1:
    WRange[0] = List[i][0]
  elif List[i][2] == 2:
    WRange[1] = List[i][0]
  elif List[i][2] == 3:
    HRange[0] = List[i][1]
  else List[i][2] == 4:
    HRange[1] = List[i][1]
if WRange[1]-WRange[0] >0:
  W = WRange[1]-WRange[0]
else:
  W = 0
if HRange[1]-HRange[0] >0:
  H = HRange[1]-HRange[0]
else:
  H = 0
res = H * W
print(res)

Submission status: Runtime Error

Solution code:
import sys

def nextrec(coor,pt):
    if pt[2]==1:
        coor[0]=min(max(coor[0],pt[0]),coor[2])
    elif pt[2]==2:
        coor[2]=max(min(coor[2],pt[0]),coor[0])
    elif pt[2]==3:
        coor[1]=min(max(coor[1],pt[1]),coor[3])
    elif pt[2]==4:
        coor[3]=max(min(coor[3],pt[1]),coor[1])
def main(w,h,n,pts):
    rec=[0,0,w,h]
    for x in range(n):
        nextrec(rec,pt[x]):
    return (rec[0]-rec[2])*(rec[1]-rec[3])

w,h,n=map(int,sys.stdin.readline().strip().split())
pts=[list(map(int,sys.stdin.readline().strip().split())) \
    for x in range(n)]

print(main(w,h,n,pts))

Submission status: Runtime Error

Solution code:
def p_grid(w, h):
	for i in range(h):
		for j in range(w):
			print(grid[j + w*i], end='')
		print()

def coloring():
    line = input()
    words = line.split()
    W = int(words[0])
    H = int(words[1])
    N = int(words[2])

    x = 0
    y = 0
    w = W
    h = H

    grid = []

    for i in range(h):
        for j in range(w):
            grid.append(0)

    for i in range(N):
      s = input()
      ws = s.split()
      x = int(ws[0])
      y = int(ws[1])
      a = int(ws[2])
      if a == 1 or a==3:
        #rect = x * y
        for i in range(y):
            for j in range(x):
                grid[j + w * i] = 1

        for i in range(h):
		    for j in range(w):
			    print(grid[j + w*i], end='')
		    print()

      if a == 2:
        #rect = (w - x) * y
        for i in range(y):
            for j in range(x,w):
                grid[j + w*i] = 1

        for i in range(h):
		    for j in range(w):
			    print(grid[j + w*i], end='')
		    print()

      if a == 4:
        #rect = x * (h - y)
        for i in range(y,h):
            for j in range(x):
                grid[j + w*i] = 1

        for i in range(h):
		    for j in range(w):
			    print(grid[j + w*i], end='')
		    print()
        
    print(grid.count(0))




coloring()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
W,H,N=map(int.input().split())
a,b,c,d=0,W,0,H

for i in range(N):
  x,y,A=map(int.input().split())
  if A==1:
    a=max(a,x)
  if A==2:
    b=min(b,x)
  if A==3:
    c=max(c,y)
  if A==4:
    d=min(d,y)
  
print(max(0,b-a)*max(0,d-c))

Submission status: Runtime Error

Solution code:
W,H,N=map(int.input().split())
a,b,c,d=0,W,0,H

for i in range(N):
  x,y,A=map(int.input().split())
  if A==1: a=max(a,x)
  if A==2: b=min(b,x)
  if A==3: c=max(c,y)
  if A==4: d=min(d,y)
  
print(max(0,b-a)*max(0,d-c))

Submission status: Runtime Error

Solution code:
W, H, N=map(int, input().split())
hen=[0,W,0,H]
for _ in range(N):
  x, y, a=map(int, input().split())
  if a==1:
    heb[a-1]=max(hen[a-1], x)
  elif a==2:
    hen[a-1]=min(hen[a-1], x)
  elif a==3:
    hen[a-1]=max(hen[a-1], y)
  elif a==4:
    hen[a-1]=min(hen[a-1], y)
yoko=hen[1]-hen[0]
tate=hen[3]-hen[2]
if yoko<0 or tate<0:
  ans=0
else:
  ans=yoko*tate
print(ans)

Submission status: Runtime Error

Solution code:
w,h,n=map(int, input().split())
x=[]
y=[]
a=[]
for i in range(n):
  s=map(int, input().split())
  x.append(s[0])
  y.append(s[1])
  a.append(s[2])
x_l=0
x_h=w
y_l=0
y_h=h
for i in range(n):
  if a[i]==1:
    if x_l<x[i]:
      x_l=x[i]
  elif a[i]==2:
    if x_h>x[i]:
      x_h=x[i]
  elif a[i]==3:
    if y_l<y[i]:
      y_l=y[i]
  else:
    if y_h>y[i]:
      y_h=y[i]
s=(x_h-x_l)*(y_h-y_l)
if s>0:
  print(s)
else:
  print("0")

Submission status: Runtime Error

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

S = [[1] * W for _ in range(H)]
for x, y, a in xya:
    if a == 1:
        for i in range(H):
            for j in range(x):
                S[i][j] = 0
    elif a == 2:
        for i in range(x, W):
            for j in range(x, W)
                S[i][j] = 0
    elif a == 3:
        for i in range(y):
            for j in range(W):
                S[i][j] = 0
    else:
        for i in range(y, H):
            for j in range(W):
                S[i][j] = 0
print(sum(S))

Submission status: Runtime Error

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)
  if a==2:
    x2=min(x2,x)
  if a==3:
    y1=max(y1,y)
  if a==4:
    y2=min(y2,y)
if x2<x1 or y2<y1
  print(0)
else:
  print((x2-x1)*(y2-y1))

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split())
xl, xr = 0, w
yd, yu = 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x < xl:
            continue
        elif xl <= x <= xr:
            xl = x
        else:
            xl, xr = 0
    elif a == 2:
        if xr < x:
            continue
        elif xl <= x <= xr:
            xr = x
        else:
            xl, xr = 0, 0
    elif a == 3:
        if y < yd:
            continue
        elif yd <= y <= yu:
            yd = y
        else:
            yd, yu = 0, 0
    elif a == 4:
        if y > yu:
            continue
        elif yd <= y <= yu:
            yu = y
        else:
            yd, yu = 0, 0

print((xr - xl) * (yu - yd))

Submission status: Runtime Error

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

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))

# print("test")
# print(W,H,N)

#solve
xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        # Xiより小さいを黒
        xb = max(xb, X[_])
    elif A[_] == 2:
        # Xiより大きいを黒
        xe = min(xe, X[_])
    elif A[_] == 3:
        # Yiより小さいを黒
        yb = max(yb, Y[_])
    else:
        # Yiより大きいを黒
        ye = min(ye, [_])
    
    # check
    if (xe - xb) <= 0 or (ye - yb) <= 0:
        print(0)
        import sys
        sys.exit()

ans = (xe - xb) * (ye - yb)
print(ans)

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split())
ll_x, ll_y, tr_x, tr_y = 0, 0, w, h
for q in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        ll_x = max(ll_x, x)
    elif a == 2:
        tr_x = min(tr_x, x)
    elif a == 3:
        ll_y = max(ll_y, y)
    elif a == 4:
        tr_y = min(tr_y, y)
print(f"({ll_x}, {ll_y}), ({tr_x}, {tr_y})")
ans = (tr_x - ll_x) * (tr_y - ll_y)
print(ans if ans > 0 else 0)

Submission status: Runtime Error

Solution code:
w, h, n  = map(int, input().split())
m = [[1 for i in range(w)] for j in range(h)]

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


total = 0
for row in m:
    total += sum(row)
print(total)

Submission status: Runtime Error

Solution code:


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

data = Zeros(h,w)

for i in range(n):
    q = list(map(int, input().split()))
    a,b,c,d = 0,w,0,h
    if(q[2]==1):
        b = q[0]
    elif(q[2]==2):
        a = q[0]
    elif(q[2]==3):
        d = q[1]
    elif(q[2]==4):
        c = q[1]
    for j in range(a,b):
        for k in range(c,d):
            data[k][j]=1
    #print(data)

print(w*h-sum([sum(data[j]) for j in range(h)]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

d = [[0], [W], [0], [H]]

for x, y, a in xya:
    if a == 1 or a == 2:
        d[a-1] += [x]
    else:
        d[a-1] += [y]

if (max(d[0]) - min(d[1])) > 0 and (max(d[2]) - min(d[3]) > 0:
    ret = (max(d[0]) - min(d[1])) * (max(d[2]) - min(d[3]))
    print(max(ret, 0))
else:
    print(0)

Submission status: Runtime Error

Solution code:
w,h,n = map(int,input().split())
d = {1:0,2:h,3:0,4:w}
for _ in range(n):
  x,y,a = map(int,input().split())
  if a %2:
    d[a] = max(d[a],[x,y][a//2]) 
  else:
    d[a] = min(d[a],[x,y][a//2])

if d[1] > d[2] or d[3] > d[4]:
  print(0)
else:
  ans = (d[2]-d[1]+1) * (d[4]-d[3]+1)
  print(ans)

Submission status: Runtime Error

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

grouped_dots = {1: [], 2: [], 3: [], 4: []}

for _ in range(n):
  dot = append(list(map(int, input().split(" "))))
  if dot[-1] in (1, 2):
    grouped_dots[dot[-1]].append(dot[0])
  else:
    grouped_dots[dot[-1]].append(dot[1])

x_min = max(grouped_dots[1]) if len(grouped_dots[1]) > 1 else 0
x_max = min(grouped_dots[2]) if len(grouped_dots[2]) > 1 else w
y_min = max(grouped_dots[3]) if len(grouped_dots[3]) > 1 else 0
y_max = min(grouped_dots[4]) if len(grouped_dots[4]) > 1 else h
x = 0 if x_max - x_min < 0 else x_max - x_min
y = 0 if y_max - y_min < 0 else y_max - y_min
print(x * y)