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

Solution code:
width, height, n = [int(e) for e in input().split()]
lst = [[0 * width]] * height

for _ in range(n):
    x, y, a = [int(e) for e in input().split()]
    
    if a == 1:
        for i in range(x):
            for j in range(height):
                lst[j][i] = 1
    elif a == 2:
        for i in range(x, width):
            for j in range(height):
                lst[j][i] = 1
    elif a == 3:
        for i in range(y):
            for j in range(width):
                lst[i][j] = 1
    elif a == 4:
        for i in range(y, height):
            for j in range(width):
                lst[i][j] = 1
        

total = 0
for row in lst:
    for column in row:
        if column == 0:
            total += 1

print(total)

Submission status: Runtime Error

Solution code:
width, height, n = [int(e) for e in input().split()]
lst = [[0 * width]] * height

for _ in range(n):
    x, y, a = [int(e) for e in input().split()]
    
    if a == 1:
        for i in range(x):
            for j in range(height):
                lst[i][j] = 1
    elif a == 2:
        for i in range(x, width):
            for j in range(height):
                lst[i][j] = 1
    elif a == 3:
        for i in range(y):
            for j in range(width):
                lst[i][j] = 1
    elif a == 4:
        for i in range(y, height):
            for j in range(width):
                lst[i][j] = 1
        

total = 0
for row in lst:
    for column in row:
        if column == 0:
            total += 1

print(total)

Submission status: Runtime Error

Solution code:
W, H, N = [int(x) for x in input().strip().split()]
x_min = 0
y_min = 0

for i in range(N):
    x, y, a = [int(x) for x in input().strip().split()]
    if a == 1 and x_min < x:
        x_min = x
    elif a == 2 and W > x:
        W = x
    elif a == 3 and y_min < y:
        y_min = y
    elif a == 4 and H > y:
        H = y
    
if x_min > w or y_min > H:
    print('0')
else:
    print('(W - x_min)*(H - y_min)')

Submission status: Runtime Error

Solution code:
W, H, N = [int(x) for x in input().strip().split()]
x_min = 0
y_min = 0

for i in range(N):
    x, y, a = [int(x) for x in input().strip().split()]
    if a == 1 and x_min < x:
        x_min = x
    elif a == 2 and W > x:
        W = x
    elif a == 3 and y_min < y:
        y_min = y
    elif a == 4 and H > y:
        H = y
    
if x_min > w or y_min > H:
    print('0')
else:
    print((W - x_min)*(H - y_min))

Submission status: Runtime Error

Solution code:
# coding: utf-8
"""Snuke's Coloring 2 (ABC Edit)

@author: hijiri.n
@modified: 11-19-2016

"""

def data(): return list(map(int, input().split()))


def solve(init, point):
    w, h, N = init
    rect = [0, w, 0, h]

    for p in point:
        x, y, a = p

        if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
            rect[a - 1] = [x, y][a > 2]

        if rect[1] <= rect[0] or rect[3] <= rect[2]:
            return 0
        
    return (rect[1] - rect[0]) * (rect[3] - rect[2])

i_in = data()
p_in = [data() for _ in i[-1]]
print(solve(i_in, p_in))

Submission status: Runtime Error

Solution code:
import sys

inputdata=sys.stdin.readlines()
whn=int(inputdata[0].split( ))
W=whn[0]
H=whn[1]
N=whn[2]
data1=[]
data2=[]
data3=[]
data4=[]
for i in inputdata:
	if i[-1]=="1":
		data1.append(int(i.split( )))
	elif i[-1]=="2":
		data2.append(int(i.split( )))
	elif i[-1]=="3":
		data3.append(int(i.split( )))	
	elif i[-1]=="4":
		data4.append(int(i.split( )))
		
a=0
for i in data1:
	if a<i:
		a=i
b=W
for i in data2:
	if b>i:
		b=i

c=0
for i in data3:
	if c<i:
		c=i					
d=H
for i in data4:
	if d>i:
		d=i
 		
if c>=d:
 	print("0")
elif b<=a:
 	print("0")
else:
 	print(str((d-c)*(b-a)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
 
w, h, N = list(map(int, input().split()))
 
rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if [1, -1][a % 2] * ([a > 2] - rect[a - 1]) < 0:
        rect[a - 1] = [x, y][a > 2]
 
length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))

Submission status: Runtime Error

Solution code:

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

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

ans=(w-wo)*(h-ho)

if wo>=w or h0>=h: print(0)
else: print(ans)

Submission status: Runtime Error

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

min_x_1 = w
max_x_2 = 0
min_y_3 = h
max_y_4 = 0
for i in range(n):
    ai = xya[i][2]
    if ai == 1:
        if xya[i][0] < min_x_1:
            min_x_1 = xya[i][0]
    if ai == 2:
        if xya[i][0] > max_x_2:
            max_x_2 = xya[i][0]
    if ai == 3:
        if xya[i][1] < min_y_3:
            min_y_3 = xya[i][1]
    if ai == 4:
        if xya[i][1] > max_y_4:
            max_y_4 = xya[i][1]

x = min_x_1 - max_x_2
if x <= 0:
    print("0")
else:
    y = min_y_3 - max_y_4
    if y <= 0:
        print("0")
    else:
        print(str(x * y))
return 0

Submission status: Runtime Error

Solution code:
w,h,n=map(int,raw_input().split())
x1=0,x2=w,y1=0,y2=h
for i in range(n):
    x,y,a=map(int,raw_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)
print max(0,x2-x1)*max(0,y2-y1)

Submission status: Runtime Error

Solution code:
def main():
    W,H,N = map(int , raw_input().split())
    white = {"l_bottom":[0,0],"r_top":[W,H]}
    
    areaZero = False
    
    for i in xrange(N):
        x,y,a = map(int,raw_input().split())
        if a == 1:
            if x > white['r_top'][0]:
                areaZero = True 
                continue
            if x > white['l_bottom'][0]:
                white['l_bottom'][0] = x
                continue
        if a == 2:
            if x <  white['l_bottom'][0]:
                areaZero = True 
                continue
            if x < white['r_top'][0]:
                white['r_top'][0] = x
                continue
        if a ==3 :
            if y > white['r_top'][1]:
                areaZero = True 
                continue
            if y > white['l_bottom'][1]:
                white['l_bottom'][1] = y
                continue
        if a == 4 :
            if y < white['l_bottom'][1]:
                areaZero = True 
                continue
            if y < white['r_top'][1]:
                white['r_top'][1] = y
                continue
    if areaZero == True:
        print 0
    else:
        print (white['r_top'][0]  - white['l_bottom'][0]) * (white['r_top'][1]  - white['l_bottom'][1])

if __name__ == '__main__'
    main()

Submission status: Runtime Error

Solution code:
W = 0
H = 0
maxa_1 = 0
mina_2 = 0
maxa_3 = 0
mina_4 = 0

count = 0
for line in l:
	if count == 0:
		W = line[0]
		H = line[1]
		S = W * H

		maxa_1 = 0
		mina_2 = W
		maxa_3 = 0
		mina_4 = H

	else:
		if line[2] == 1:
			maxa_1 = max(maxa_1, line[0], 0)
		if line[2] == 2:
			mina_2 = min(mina_2, line[0], W)
		if line[2] == 3:
			maxa_3 = max(maxa_3, line[1], 0)
		if line[2] == 4:
			mina_4 = min(mina_4, line[1], H)

	count += 1

print((mina_2-maxa_1) * (mina_4-maxa_3))

Submission status: Runtime Error

Solution code:
def read():
	return [int(i) for i in input().split(' ')]
W, H, N = read()
x = [0] * N
y = [0] * N
a = [0] * N
for i in range(N):
	x[i], y[i], a[i] = read()
new_x = [0] + x + [W]
new_y = [0] + y + [H]
for inx in range(N):
	if(a[inx] == 1):
		new_x = [num for num in new_x if num >= x[inx]] 
	elif(a[inx] == 2):
		new_x = [num for num in new_x if num <= x[inx]] 
	elif(a[inx] == 3):
		new_y = [num for num in new_y if num >= y[inx]] 
	else:
		new_y = [num for num in new_y if num <= y[inx]] 
area = (max(new_x) - min(new_x)) * (max(new_y) - min(new_y))
print(area)