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:
# 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
 
        rect[a - 1] = [min, max][a % 2](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])
 
# Input init & points data
i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print(solve(i_in, p_in))

Submission status: Accepted

Solution code:
import sys

W, H, N = map(int, sys.stdin.readline().split())
top = H
left = 0
right = W
down = 0
for _ in xrange(N):
    x, y, a = map(int, sys.stdin.readline().split())
    if a == 1:
        left = max(left,x)
    elif a == 2:
        right = min(right,x)
    elif a == 3:
        down = max(down,y)
    elif a == 4:
        top = min(top,y)
    else:
        pass

print (max(top - down, 0)) * (max(right - left, 0))

Submission status: Accepted

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]) if a <= 2 else (rect[3] <= rect[2]):
            return 0
        
    return (rect[1] - rect[0]) * (rect[3] - rect[2])

# Input init & points data
i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print(solve(i_in, p_in))

Submission status: Accepted

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

# Input init & points data
i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print(solve(i_in, p_in))

Submission status: Accepted

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():
    w, h, N = data()
    rect = [0, w, 0, h]

    for i in range(N):
        x, y, a = data()
        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])

print(solve())

Submission status: Accepted

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():
    w, h, N = data()
    rect = [0, w, 0, h]

    for i in range(N):
        x, y, a = data()
        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]) <= 0 & (rect[3] - rect[2]) <= 0:
            return 0

    return (rect[1] - rect[0]) * (rect[3] - rect[2])

print(solve())

Submission status: Accepted

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

field = [[0 for x in range(w)] for y in range(h)]

a = [list(map(int, input().split())) for x in range(n)]

def a1(line):
    for l in field:
        for x in range(line[0]):
            l[x] = 1

def a2(line):
    for l in field:
        for x in range(line[0], w):
            l[x] = 1

def a3(line):
    for y in range(line[1]):
        field[h - y - 1] = [1 for x in range(w)]

def a4(line):
    for y in range(line[1], h):
        field[h - y - 1] = [1 for x in range(w)]

for line in a:
    globals()["a" + str(line[2])](line[:2])

print(list(itertools.chain(*field)).count(0))

Submission status: Accepted

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

W, H, N = list(map(int, input().split()))
minX = 0
maxX = W
minY = 0
maxY = H

def calc():
    if maxX < minX or maxY < minY:
        return 0
    return (maxX - minX) * (maxY - minY)

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a is 1:
        if minX < x:
            minX = x
    elif a is 2:
        if maxX > x:
            maxX = x
    elif a is 3:
        if minY < y:
            minY = y
    elif a is 4:
        if maxY > y:
            maxY = y

print(calc())

Submission status: Accepted

Solution code:
W,H,N = [int(x) for x in raw_input().split(" ")]
x = []
y = []
a = []

for n in range(N):
	i,j,k = [int(w) for w in raw_input().split(" ")]
	x.append(i)
	y.append(j)
	a.append(k)

X = 0
Y = 0

for i in range(N):
	if a[i] == 1:
		X = max(X,x[i])

	elif a[i] == 2:
		W = min(W,x[i])

	elif a[i] == 3:
		Y = max(Y,y[i])

	elif a[i] == 4:
		H = min(H,y[i])

if X >= W:
	print 0
elif Y >= H:
	print 0
else:
	print (H-Y)*(W-X)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
W,H,N = map(int,raw_input().split())
arr = []
for i in xrange(N):
    arr.append(map(int,raw_input().split()))

minx=0
miny=0
maxx=W
maxy=H

for r in arr:
    (x,y,a) = r
    if a==1 and x > minx:
        minx = x
    elif a==2 and x < maxx:
        maxx = x
    elif a==3 and y > miny:
        miny = y
    elif a==4 and y < maxy:
        maxy = y
xx = maxx-minx
yy = maxy-miny

r = 0 if xx < 0 or yy < 0 else (xx * yy)
print(r)

Submission status: Accepted

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] * ([x, y][a > 2] - rect[a - 1]) < 0:
        rect[a - 1] = [x, y][a > 2]

w, h = rect[1] - rect[0], rect[3] - rect[2]
if w > 0 and h > 0:
    print(w * h)
else:
    print(0)

Submission status: Accepted

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] * ([x, y][a > 2] - rect[a - 1]) < 0:
        rect[a - 1] = [x, y][a > 2]

w, h = rect[1] - rect[0], rect[3] - rect[2]
print([0, w * h][w > 0 and h > 0])

Submission status: Accepted

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] * ([x, y][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: Accepted

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()))
    rect[a-1]=(lambda c,r,p:[r,c][p*(c-r)<0])([x,y][a>2],rect[a-1],[1,-1][a%2])

length=lambda x:[x,0][x<0]
print(length(rect[1]-rect[0])*length(rect[3]-rect[2]))

Submission status: Accepted

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()))
    rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])([x, y][a > 2], rect[a - 1], [1, -1][a % 2])

length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))

Submission status: Accepted

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()))
    rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])([x, y][a > 2], rect[a - 1], int(not a % 2) - int(a % 2))

length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))

Submission status: Accepted

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()))
    rect[a - 1] = (lambda c, r, p: [r, c][[c < r, c > r][p]])([x, y][a > 2], rect[a - 1], a % 2)

length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))

Submission status: Accepted

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=max(wo, x)
    if a==2: w=min(w, x)
    if a==3: ho=max(ho, y)
    if a==4: h=min(h, y)

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

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

Submission status: Accepted

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:
        if x>wo: wo=x
    if a==2:
        if x<w: w=x
    if a==3:
        if y>ho: ho=y
    if a==4:
        if y<h: h=y

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

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xmax=w
xmin=ymin=0
ymax=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)
    else:
        ymax=min(ymax,y)

width=max(0,xmax-xmin)
height=max(0,ymax-ymin)

print(width*height)

Submission status: Accepted

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

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

    print(sum(sum(line) for line in field))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
p = [0, 0]
q = [w, h]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if p[0] < x:
            p[0] = x
    if a == 2:
        if x < q[0]:
            q[0] = x
    if a == 3:
        if p[1] < y:
            p[1] = y
    if a == 4:
        if y < q[1]:
            q[1] = y

    if p[0] > q[0]:
        q[0] = p[0]
    if p[1] > q[1]:
        q[1] = p[1]

        
s = (q[0] - p[0])*(q[1] - p[1])

print(s)

Submission status: Accepted

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

max_x_1 = 0
min_x_2 = w
max_y_3 = 0
min_y_4 = h
for i in range(n):
    ai = xya[i][2]
    if ai == 1:
        if xya[i][0] > max_x_1:
            max_x_1 = xya[i][0]
    if ai == 2:
        if xya[i][0] < min_x_2:
            min_x_2 = xya[i][0]
    if ai == 3:
        if xya[i][1] > max_y_3:
            max_y_3 = xya[i][1]
    if ai == 4:
        if xya[i][1] < min_y_4:
            min_y_4 = xya[i][1]

x = min_x_2 - max_x_1
if x <= 0:
    print("0")
else:
    y = min_y_4 - max_y_3
    if y <= 0:
        print("0")
    else:
        print(x * y)

Submission status: Accepted

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

for i in range(n):
    li.append([int(i) for i in input().split()])

flag = [[0 for i in range(w)] for j in range(h)]
count = 0

for i in range(n):
    if(li[i][2] == 1):
        for x in range(li[i][0]):
            for y in range(h):
                flag[y][x] = 1
    elif(li[i][2] == 2):
        for x in range(li[i][0], w):
            for y in range(h):
                flag[y][x] = 1
    elif(li[i][2] == 3):
        for x in range(w):
            for y in range(li[i][1]):
                flag[y][x] = 1
    elif(li[i][2] == 4):
        for x in range(w):
            for y in range(li[i][1], h):
                flag[y][x] = 1

for x in range(w):
    for y in range(h):
        if(flag[y][x] == 0):
            count+=1

print(count)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
xl=0
xh=W
yl=0
yh=H
allblack=False
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:
        allblack=True
        break
print(0 if allblack else (xh-xl)*(yh-yl))

Submission status: Accepted

Solution code:
#abc047_b

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

if xmin<=xmax:
 res=0
elif ymin<=ymax:
 res=0
else:
 res=(xmin-xmax)*(ymin-ymax)
print res

Submission status: Accepted

Solution code:
W,H,N = (int(i) for i in input().split())
fill_map = [[ 0 for i in range(H)] for j in range(W)]
def count(fill_map):
    counter = 0
    for i in range(W):
        for j in range(H):
            if fill_map[i][j] == 0:
                counter += 1
    return counter

def _fill(l1,l2,fill_map):
    for i in range(l1[0],l2[0]+1):
        for j in range(l1[1],l2[1]+1):
            fill_map[i][j] = 1
            
def fill(axis,direction,fill_map):
    if axis == 0:
        if direction == 0:
            #fill left side
            _fill([0,0],[x-1,H-1],fill_map)
        else:
            #fill right side
            _fill([x,0],[W-1,H-1],fill_map)
    else:
        if direction == 0:
            #fill down side
            _fill([0,0],[W-1,y-1],fill_map)
        else:
            #fill upper side
            _fill([0,y],[W-1,H-1],fill_map)



for i in range(N):
    x,y,a = (int(i) for i in input().split())
    if a == 1:
        fill(0,0,fill_map)
    elif a == 2:
        fill(0,1,fill_map)
    elif a == 3:
        fill(1,0,fill_map)
    elif a == 4:
        fill(1,1,fill_map)

result = count(fill_map)
print(result)

Submission status: Accepted

Solution code:
W,H,N=map(int,raw_input().split())
X=[0,W]
Y=[0,H]
for _ in xrange(N):
  x,y,a=map(int,raw_input().split())
  if a==1:
    X[0]=max(X[0],x)
  elif a==2:
    X[1]=min(X[1],x)
  elif a==3:
    Y[0]=max(Y[0],y)
  elif a==4:
    Y[1]=min(Y[1],y)
if X[1]<=X[0] or Y[1]<=Y[0]: print 0
else: print (X[1]-X[0])*(Y[1]-Y[0])

Submission status: Accepted

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

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

for i in range(n):
    x,y,a = map(int,raw_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)

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:
a,b,c=list(map(int,input().split()))

X=[[0 for i in range(a)] for j in range(b)]

d=[input().split() for i in range(c)]

for i in range(c):
    if d[i][2]=="1":
        for j in range(b):
            for k in range(int(d[i][0])):
                X[j][k]=1
    elif d[i][2]=="2":
        for j in range(b):
            for k in range(a-1,int(d[i][0])-1,-1):
                X[j][k]=1
    elif d[i][2]=="3":
        for j in range(int(d[i][1])):
            for k in range(a):
                X[j][k]=1
    else:
        for j in range(b-1,int(d[i][1])-1,-1):
            for k in range(a):
                X[j][k]=1


c=0
for i in range(b):
    for j in range(a):
        if X[i][j]==0:
            c+=1

print(c)

Submission status: Accepted

Solution code:
w,h,n=map(int,raw_input().split())
x1,x2,y1,y2=0,w,0,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: Accepted

Solution code:
W, H, N = map(int, raw_input().split())
x = []
y = []
a = []
for i in xrange(N):
    mem = map(int, raw_input().split())
    x.append(mem[0])
    y.append(mem[1])
    a.append(mem[2])

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

for (xi, yi, ai) in zip(x, y, a):
    if ai == 1:
        l = (l < xi) and xi or l
    elif ai == 2:
        r = (xi < r) and xi or r
    elif ai == 3:
        b = (b < yi) and yi or b
    elif ai == 4:
        t = (yi < t) and yi or t
        
h = (r > l) and r - l or 0
v = (t > b) and t - b or 0
print h * v

Submission status: Accepted

Solution code:
import numpy as np

if __name__ == "__main__":
	w,h,n = map(int, raw_input().split())
	fi = np.zeros([h,w])

	for i in range(n):
		x,y,a = map(int, raw_input().split())
		if(a == 1):
			for j in range(h):
				for k in range(x):
					fi[j][k] = 1
		elif(a == 2):
			for j in range(h):
				for k in range(x, w):
					fi[j][k] = 1
		elif(a == 3):
			for j in range(h-y,h):
				for k in range(w):
					fi[j][k] = 1
		elif(a == 4):
			for j in range(h-y):
				for k in range(w):
					fi[j][k] = 1


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

Submission status: Accepted

Solution code:
w,h,n = map(int,raw_input().split(" "))
lines = map(lambda x : map(int,x.split(" ")),[raw_input() for var in range(n)])

x_min,x_max,y_min,y_max = 0,w,0,h
for var in lines:
    x,y,a = var
    if a == 1:
        x_min = x_min if x_min > x else x
    elif a == 2:
        x_max = x_max if x_max < x else x
    elif a == 3:
        y_min = y_min if y_min > y else y
    elif a == 4:
        y_max = y_max if y_max < y else y

print (lambda x: x if x > 0 else 0  )(x_max-x_min)*(y_max - y_min)

Submission status: Accepted

Solution code:
def readints(): return map(int,input().split())

W, H, N = readints()
d = [[1 for w in range(W)] for h in range(H)]

for _ in range(N):
    x, y, a = readints()
    if a == 1:
        for h in range(H):
            for w in range(x):
                d[h][w] = 0
                
    elif a == 2:
        for h in range(H):
            for w in range(x,W):
                d[h][w] = 0

    elif a == 3:
        for h in range(y):
            for w in range(W):
                d[h][w] = 0

    else:
        for h in range(y,H):
            for w in range(W):
                d[h][w] = 0

res = 0
for h in range(H):
    res += sum(d[h])

print(res)

Submission status: Accepted

Solution code:
def Main():
    w,h ,n = map(int,input().split())
    mnx = 0
    mny = 0
    mxx = w
    mxy = h

    for i in range(n):
        x,y ,a = map(int ,input().split())
        if a == 1:
            mnx = max(mnx, x)
        elif a == 2:
            mxx = min(mxx, x)
        elif a == 3:
            mny = max(mny, y)
        elif a == 4:
            mxy = min(mxy, y)

    if mxy <= mny or mxx <= mnx:
        print(0)
    else:
        print((mxy - mny)*(mxx - mnx))


if __name__ == '__main__':
    Main()

Submission status: Accepted

Solution code:
w, h, n = list(map(int, input().split()))
ma1 = ma2 = ma3 = ma4 = 0
flag = flag1 = True
while(n):
	x, y, a = list(map(int, input().split()))
	if a == 1:
		if x > ma1:
			ma1 = x
	elif a == 2:
		if flag:
			ma2 = x
			flag = False
		if x < ma2:
			ma2 = x
	elif a == 3:
		if y > ma3:
			ma3 = y
	elif a == 4:
		if flag1:
			ma4 = y
			flag1 = False
		if y < ma4:
			ma4 = y
	n -= 1
 
if ma1 and ma2:
	if ma1 >= ma2:
		width = 0
	else:
		width = abs(ma1-ma2)
else:
	if ma1 == 0 and ma2 == 0:
		width = w
	elif ma1 == 0:
		width = ma2
	elif ma2 == 0:
		width = w - ma1
if ma3 and ma4:
	if ma3 >= ma4:
		height = 0
	else:
		height = abs(ma3-ma4)
else:
	if ma3 == 0 and ma4 == 0:
		height = h
	elif ma3 == 0:
		height = ma4
	elif ma4 == 0:
		height = h - ma3
 
print(width*height)

Submission status: Accepted

Solution code:
w,h,n=map(int,raw_input().split())
l=[['.' for i in range(w)] for j in range(h)]
for i in range(n):
    x,y,a=map(int,raw_input().split())
    if a==1:
        for i in range(h):
            for j in range(x):
                l[i][j]='#'
    elif a==2:
        for i in range(h):
            for j in range(x,w):
                l[i][j]='#'
    elif a==3:
        for i in range(y):
            l[i]=['#' for j in range(w)]
    else:
        for i in range(y,h):
            l[i]=['#' for j in range(w)]

ans=chk=0
for i in l:
    ans+=i.count('.')
print ans

Submission status: Accepted

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


def main():
    w, h, n = map(int, input().split())
    x_lb = y_lb = 0
    x_ub = w
    y_ub = h
    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            x_lb = max(x_lb, x)
        elif a == 2:
            x_ub = min(x_ub, x)
        elif a == 3:
            y_lb = max(y_lb, y)
        else:
            y_ub = min(y_ub, y)
    print(max(0, (x_ub - x_lb)) * max(0, (y_ub - y_lb)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
W, H, N = map(int, raw_input().split())
b_w = [0, W]
b_h = [0, H]

for i in range(N):
    # ta_list.append(map(int, raw_input().split()))
    x, y, a = map(int, raw_input().split())
    if a == 1 and x > b_w[0]:
        b_w[0] = x
    elif a == 2 and x < b_w[1]:
        b_w[1] = x
    elif a == 3 and y > b_h[0]:
        b_h[0] = y
    elif a == 4 and y < b_h[1]:
        b_h[1] = y

print max(b_w[1]-b_w[0], 0) * max(b_h[1]-b_h[0], 0)

Submission status: Accepted

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

x1, y1, x2, y2 = 0, 0, w, 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 x1 < x2 and y1 < y2:
    print((x2 - x1) * (y2 - y1))
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = input().split()              
w, h, n = int(w), int(h), int(n)       
x = []                                 
y = []                                 
a = []                                 
                                       
for _ in range(n):                     
    x_, y_, a_ = input().split()       
    x.append(int(x_))                  
    y.append(int(y_))                  
    a.append(int(a_))                  
W = w                                  
H = h                                  
w_r = w                                
w_l = 0                                
h_u = h                                
h_l = 0                                
for i in range(n):                     
    if a[i] is 1 and x[i]>w_l:         
        w_l = x[i]                     
    if a[i] is 2 and x[i]<w_r:         
        w_r = x[i]                     
    if a[i] is 3 and y[i]>h_l:         
        h_l = y[i]                     
    if a[i] is 4 and y[i]<h_u:         
        h_u = y[i]                     
                                       
ans = (w_r - w_l)*(h_u - h_l)          
if (w_r - w_l) < 0 or (h_u - h_l) < 0: 
    ans = 0                            
print(ans)

Submission status: Accepted

Solution code:
def makemap(x,y):
    multilist = [[0 for col in range(y)] for row in range(x)]
    return multilist

def drow(X,Y,x,y,a,multilist):
    if a ==1 :
        for i in range(0,x):
            for j in range(0,Y):
                multilist[i][j]=1
    elif a ==2 :
        for i in range(x,X):
            for j in range(0,Y):
                multilist[i][j]=1
         
    elif a ==3 :
        for i in range(0,X):
            for j in range(0,y):
                multilist[i][j]=1
         
    elif a ==4 :
        for i in range(0,X):
            for j in range(y,Y):
                multilist[i][j]=1
    
    return multilist
    

def main():
    X,Y,N = map(int,input().split())
    mapx=makemap(X,Y)
    count = 0
    for k in range(0,N):
        x,y,a = map(int,input().split())
        mapx = drow(X,Y,x,y,a,mapx)
    for i in range(0,X):
        for j in range(0,Y):
            if mapx[i][j]==0:
                count+=1
    print(count)
    
main()

Submission status: Accepted

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

max_x=w
min_x=0
max_y=h
min_y=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        min_x=max(x,min_x)
    if a==2:
        max_x=min(x,max_x)
    if a==3:
        min_y=max(y,min_y)
    if a==4:
        max_y=min(y,max_y)
wid=max_x-min_x if max_x>=min_x else 0
hei=max_y-min_y if max_y>=min_y else 0
print(wid*hei)

Submission status: Accepted

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

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

Submission status: Accepted

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

w_min = 0; w_max = W
h_min = 0; h_max = H
curr_area = W * H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > w_min:
        if x >= w_max:
            curr_area = 0
            break
        else:
            w_min = x

    elif a == 2 and x < w_max:
        if x <= w_min:
            curr_area = 0
            break
        else:
            w_max = x
    elif a == 3 and y > h_min:
        if y >= h_max:
            curr_area = 0
            break
        else:
            h_min = y
    elif a == 4 and y < h_max:
        if y <= h_min:
            curr_area = 0
            break
        else:
            h_max = y
    curr_area = (w_max - w_min) * (h_max - h_min)
print(curr_area)

Submission status: Accepted

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]] 
if(not(new_x) or not(new_y)):
	print(0)
	exit()
area = (max(new_x) - min(new_x)) * (max(new_y) - min(new_y))
print(area)

Submission status: Accepted

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

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

glid = []
for i in range(H):
    l = [0]*(W)
    glid.append(l)

for s in range(N):
    x = A[s][0]
    y = A[s][1]
    a = A[s][2]
    
    if a==1:
        for t in range(H):
            for u in range(x):
                glid[t][u] = 1
        
    elif a==2:
        for t in range(H):
            for u in range(x,W,1):
                glid[t][u] = 1
    
    elif a==3:
        y_ = H-y
        for t in range(y_,H,1):
            for u in range(W):
                glid[t][u] = 1
    
    else:
        y_ = H-y
        for t in range(0,y_,1):
            for u in range(W):
                glid[t][u] = 1

counter = 0
for i in range(H):
    a = glid[i].count(0)
    counter += a

print(counter)