Problem:


Score : 200 points

Problem Statement

There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.

Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).

Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

If a_i = 1, he painted the region satisfying x < x_i within the rectangle.

If a_i = 2, he painted the region satisfying x > x_i within the rectangle.

If a_i = 3, he painted the region satisfying y < y_i within the rectangle.

If a_i = 4, he painted the region satisfying y > y_i within the rectangle.

Find the area of the white region within the rectangle after he finished painting.

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

0 ≦ x_i ≦ W (1 ≦ i ≦ N)

0 ≦ y_i ≦ H (1 ≦ i ≦ N)

W, H (21:32, added), x_i and y_i are integers.

a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

Input

The input is given from Standard Input in the following format:

W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

Now, the area of the white region within the rectangle is 9.

Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64



Sample input:
5 4 2
2 1 1
3 3 4


Sample output:
9

Submission status: Accepted

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

white = [0, W, 0, H]

points = [[int(i) for i in input().split()] for j in range(N)]

for point in points:
    if point[2] == 1:
        if point[0] > white[0]:
            white[0] = point[0]
    if point[2] == 2:
        if point[0] < white[1]:
            white[1] = point[0]
    if point[2] == 3:
        if point[1] > white[2]:
            white[2] = point[1]
    if point[2] == 4:
        if point[1] < white[3]:
            white[3] = point[1]

w = white[1] - white[0]
h = white[3] - white[2]

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
xy = []
a = []
for i in range(n):
    xy.append([li[i][0], li[i][1]])
    a.append(li[i][2])

left, right = [0, 0], [w, h]

for i in range(n):
    if a[i] == 1:
        if left[0] < xy[i][0]:
            left[0] = xy[i][0]
    elif a[i] == 2:
        if right[0] > xy[i][0]:
            right[0] = xy[i][0]
    elif a[i] == 3:
        if left[1] < xy[i][1]:
            left[1] = xy[i][1]
    else:
        if right[1] > xy[i][1]:
            right[1] = xy[i][1]

if left[0] >= right[0] or left[1] >= right[1]:
    ans = 0
else:
    ans = (right[0]-left[0]) * (right[1]-left[1])
print(str(ans))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
dots = [[0] * w for i in range(h)]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(len(dots)):
            for j in range(x):
                dots[i][j] = 1
    elif a == 2:
        for i in range(len(dots)):
            for j in range(x, w):
                dots[i][j] = 1
    elif a == 3:
        for i in range(y):
            dots[i] = [1]*w
    else:
        for i in range(y, h):
            dots[i] = [1]*w
ans = 0
for i in range(h):
    ans += dots[i].count(0)
 
print(ans)

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

X1 = 0
X2 = 0
Y1 = 0
Y2 = 0

x1, x2, y1, y2 = 0, 0, 0, 0

X = 0
Y = 0

entire = W * H

for i in range(N):
    if a[i]==1 and X1<x[i]:
        x1 = x[i] * H
        X1 = x[i]
    elif a[i]==2 and X2<(W-x[i]):
        x2 = (W-x[i]) * H
        X2 = W - x[i]
    elif a[i]==3 and Y1<y[i]:
        y1 = y[i] * W
        Y1 = y[i]
    elif a[i]==4 and Y2<(H-y[i]):
        y2 = (H-y[i]) * W
        Y2 = H - y[i]

entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))

if X1+X2>=W or Y1+Y2>=H:
    print('0')
else:
    print(entire)

Submission status: Accepted

Solution code:
W,H,N = [int(x) for x in input().split()]
a = [0]
b = [W]
c = [0]
d = [H]
for i in range(N):
    l = [int(x) for x in input().split()]
    if l[2] == 1:
        a.append(l[0])
    elif l[2] == 2:
        b.append(l[0])
    elif l[2] == 3:
        c.append(l[1])
    else:
        d.append(l[1])
aa = max(a)
bb = min(b)
cc = max(c)
dd = min(d)
if aa-bb >= 0 or cc - dd >= 0:
    print(0)
else:
    print((bb-aa)*(dd-cc))

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

X1 = 0
X2 = W
Y1 = 0
Y2 = H

for i in range(N):

    if a[i] == 1:
        X1 = max(X1, x[i])
    if a[i] == 2:
        X2 = min(X2, x[i])
    if a[i] == 3:
        Y1 = max(Y1, y[i])
    if a[i] == 4:
        Y2 = min(Y2, y[i])

if X1 >= X2 or Y1 >= Y2:
    print('0')
else:
    entire = (Y2-Y1) * (X2-X1)
    print(entire)

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

X1 = 0
X2 = 0
Y1 = 0
Y2 = 0

x1, x2, y1, y2 = 0, 0, 0, 0

X = 0
Y = 0

entire = W * H

for i in range(N):
    if a[i]==1 and X1<x[i]:
        x1 = x[i] * H
        X1 = x[i]
    elif a[i]==2 and X2<(W-x[i]):
        x2 = (W-x[i]) * H
        X2 = W - x[i]
    elif a[i]==3 and Y1<y[i]:
        y1 = y[i] * W
        Y1 = y[i]
    elif a[i]==4 and Y2<(H-y[i]):
        y2 = (H-y[i]) * W
        Y2 = H - y[i]

if (X1 + X2) >= W or (Y1 + Y2) >= H:
    print('0')
else:
    entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))
    if entire<=0:
        print('0')
    else:
        print(entire)

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

X1 = 0
X2 = 0
Y1 = 0
Y2 = 0

x1, x2, y1, y2 = 0, 0, 0, 0

X = 0
Y = 0

entire = W * H

for i in range(N):
    if a[i]==1 and X1<x[i]:
        x1 = x[i] * H
        X1 = x[i]
    elif a[i]==2 and X2<(W-x[i]):
        x2 = (W-x[i]) * H
        X2 = W - x[i]
    elif a[i]==3 and Y1<y[i]:
        y1 = y[i] * W
        Y1 = y[i]
    elif a[i]==4 and Y2<(H-y[i]):
        y2 = (H-y[i]) * W
        Y2 = H - y[i]

if (X1 + X2) >= W or (Y1 + Y2) >= H:
    print('0')
else:
    entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))

#if entire<=0:
#    print('0')
#else:
    print(entire)

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

X1 = 0
X2 = W
Y1 = 0
Y2 = H

entire = W * H

for i in range(N):
    if a[i] == 1:
        X1 = max(X1, x[i])
    if a[i] == 2:
        X2 = min(X2, x[i])
    if a[i] == 3:
        Y1 = max(Y1, y[i])
    if a[i] == 4:
        Y2 = min(Y2, y[i])

if X1 >= X2 or Y1 >= Y2:
    print('0')
else:
    entire = (Y2-Y1) * (X2-X1)
    print(entire)

Submission status: Accepted

Solution code:
def resolve():
	w, h, n = map(int, input().split())
	r = [[True]*w for _ in range(h)]
	for i in range(n):
		x, y, a = map(int, input().split())
		if a == 1:
			for j in range(h):
				for k in range(x):
					r[j][k] = False
		if a == 2:
			for j in range(h):
				for k in range(x, w):
					r[j][k] = False
		if a == 3:
			for j in range(y):
				for k in range(w):
					r[j][k] = False
		if a == 4:
			for j in range(y, h):
				for k in range(w):
					r[j][k] = False
	ans = 0
	for i in range(h):
		for j in r[i]:
			if j:
				ans += 1
	print(ans)
resolve()

Submission status: Accepted

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

X_axis = [i for i in range(W+1)]
Y_axis = [j for j in range(H+1)]

def CalcSqueare(a,b):
    if len(a)==0 or len(b)==0:
        print(0)
    else:
        print((a[-1]-a[0]) * (b[-1] - b[0]))


for i in range(N):
    x_i,y_i,a_i =map(int,input().split())

    if a_i==1:
        X_axis = [x for x in X_axis if x>=x_i]
    elif a_i==2:
        X_axis = [x for x in X_axis if x<=x_i]
    elif a_i==3:
        Y_axis = [y for y in Y_axis if y>=y_i]
    else:
        Y_axis = [y for y in Y_axis if y<=y_i]

CalcSqueare(X_axis,Y_axis)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
xl = w
xs = 0
yl = h
ys = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        xs = max(xs, x)
    elif a == 2:
        xl = min(xl, x)
    elif a == 3:
        ys = max(ys, y)
    elif a == 4:
        yl = min(yl, y)
if (yl <= ys) or (xl <= xs):
    print(0)
else:
    print((yl-ys)*(xl-xs))

Submission status: Accepted

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

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

    for j in range(h): #縦(y)
        for k in range(w): #横(x)
        
            if a==1:
                if k<x:
                    li[j][k]=1
            elif a==2:
                if k>=x:
                    li[j][k]=1
            elif a==3:
                if j<y:
                    li[j][k]=1
            else:
                if j>=y:
                    li[j][k]=1

ans=0
for tm in li:
    ans+=tm.count(0)

print(ans)

Submission status: Accepted

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

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

onelist = [0]
twolist = [w]
threelist = [0]
fourlist = [h]


for xl in xlist:
    if xl[2] == 1:
        onelist.append(xl[0])
    elif xl[2] == 2:
        twolist.append(xl[0])
    elif xl[2] == 3:
        threelist.append(xl[1])
    elif xl[2] == 4:
        fourlist.append(xl[1])

one = max(onelist)
two = min(twolist)
three = max(threelist)
four = min(fourlist)


if one > two:
    x = 0
else:
    x = two - one
if three > four:
    y = 0
else:
    y = four - three

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

Submission status: Accepted

Solution code:
def resolve():
	w, h, n = map(int, input().split())
	r = [[True]*w for _ in range(h)]
	for _ in range(n):
		ix, iy, a = map(int, input().split())
		if a == 1:
			for i in range(h):
				for j in range(ix):
					r[i][j] = False
		elif a == 2:
			for i in range(h):
				for j in range(ix, w):
					r[i][j] = False
		elif a == 3:
			for i in range(iy):
				for j in range(w):
					r[i][j] = False
		else:
			for i in range(iy, h):
				for j in range(w):
					r[i][j] = False
	ans = 0

	for row in r:
		for i in row:
			if i:
				ans += 1
	print(ans)
resolve()

Submission status: Accepted

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

sum = W*H

X1 = [0]
X2 = [W]
Y1 = [0]
Y2 = [H]
for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        X1.append(x)
    elif a == 2:
        X2.append(x)
    elif a == 3:
        Y1.append(y)
    else:
        Y2.append(y)

left = max(X1)
right = min(X2)
bottom = max(Y1)
top = min(Y2)

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x0=0
x1=w
y0=0
y1=h
for _ 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)
  elif a==4:
    y1=min(y1,y)
if y1-y0<=0 or x1-x0<=0:
  print(0)
else:
  print((y1-y0)*(x1-x0))

Submission status: Accepted

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

for i in range(N):
    X,Y,a = map(int,input().split())
    if a == 1:
        for i in range(H):
            for j in range(X):
                li[i][j] = 1
    elif a == 2:
        for i in range(H):
            for j in range(X,W):
                li[i][j] = 1
    elif a == 3:
        for i in range(Y):
            li[i] = [1]*W
    else:
        for i in range(Y,H):
            li[i] = [1]*W

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

print(counter)

Submission status: Accepted

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

x_left = 0
x_right = w
y_upper = h
y_lower = 0
t = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_left = max(x, x_left)
    elif a == 2:
        x_right = min(x, x_right)
    elif a == 3:
        y_lower = max(y, y_lower)
    else:
        y_upper = min(y, y_upper)
    if x_left < x_right and y_lower < y_upper:
        continue
    else:
        t = 1
        break
if t == 1:
    print(0)
else:
    print((x_right - x_left) * (y_upper - y_lower))

Submission status: Accepted

Solution code:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/B-ColoringEasy.py
#
w, h, n = map(int, input().split())
dots = [[0] * w for i in range(h)]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(len(dots)):
            for j in range(x):
                dots[i][j] = 1
    elif a == 2:
        for i in range(len(dots)):
            for j in range(x, w):
                dots[i][j] = 1
    elif a == 3:
        for i in range(y):
            dots[i] = [1]*w
    else:
        for i in range(y, h):
            dots[i] = [1]*w


cnt = 0
for i in range(h):
    cnt += dots[i].count(0)

print(cnt)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
w_min = 0
w_max = w
h_min = 0
h_max = w
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        if w_min < x:
            w_min = x
            
    if a == 2:
        if w_max > x:
            w_max = x
            
    if a == 3:
        if h_min < y:
            h_min = y
            
    if a == 4:
        if h_max > y:
            h_max = y

w = (w_max-w_min)
h = (h_max-h_min)
if (w > 0) and(h > 0):
    print(w*h)
    
else:
    print(0)

Submission status: Accepted

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

field = [['.' for _ in range(W)] for _ in range(H)]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(H):
            for j in range(0, x):
                field[i][j] = '#'
    elif a == 2:
        for i in range(H):
            for j in range(x, W):
                field[i][j] = '#'
    elif a == 3:
        for i in range(0, y):
            for j in range(W):
                field[i][j] = '#'
    else:
        for i in range(y, H):
            for j in range(W):
                field[i][j] = '#'

ans = 0
for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    w,h,n=map(int,input().split())
    xy=[[1]*w for i in range(h)]
    for i in range(n):
        xi,yi,ai=map(int,input().split())
        if ai==1:
            for x  in range(xi):
                for y in range(h):
                    xy[y][x]=0
        elif ai==2:
            for x  in range(xi,w):
                for y in range(h):
                    xy[y][x]=0
        elif ai==3:
            for x  in range(w):
                for y in range(yi):
                    xy[y][x]=0
        elif ai==4:
            for x  in range(w):
                for y in range(yi,h):
                    xy[y][x]=0
#        print(xy) 
    s=0
    for x in range(w):
        for y in range(h):
            s=s+xy[y][x]
    print(s)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
  A = list(map(int, input().split()))
  a.append(A)

for j in a:
  if j[2] == 1:
    x[0] = max(x[0], j[0])
  elif j[2] == 2:
    x[1] = min(x[1], j[0])
  elif j[2] == 3:
    y[0] = max(y[0], j[1])
  else:
    y[1] = min(y[1], j[1])
    
if x[0] >= x[1] or y[0] >= y[1]:
  print('0')
else:
  ans = (x[1] - x[0]) * (y[1] - y[0])
  print(int(ans))

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)
    
ans = (maxx - minx) * (maxy - miny)
print(ans if minx < maxx and miny < maxy else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
W, H, N = map(int, sys.stdin.readline().split(" "))
Map = [list(map(int,sys.stdin.readline().split(" "))) for i in range(N)]
L = 0
R = W
B = 0
T = H
 
for i in Map:
  if i[2] == 1:
    l = i[0]
    L = max(L, l)
  if i[2] == 2:
    r = i[0]
    R = min(R, r)
  if i[2] == 3:
    b = i[1]
    B = max(B, b)
  if i[2] == 4:
    t = i[1]
    T = min(T, t)
    
if R - L > 0 and T - B > 0:
  print((R - L) * (T - B))
else:
  print(0)

Submission status: Accepted

Solution code:
w, h, n = map(int, (input().split()))
x = [0, w]
y = [0, h]
A = []

for i in range(n):
    a = list(map(int, input().split()))
    A.append(a)

for j in A:
    if j[2] == 1:
        x[0] = max(x[0], j[0])
    if j[2] == 2:
        x[1] = min(x[1], j[0])
    if j[2] == 3:
        y[0] = max(y[0], j[1])
    if j[2] == 4:
        y[1] = min(y[1], j[1])

if x[0] >= x[1] or y[0] >= y[1]:
    print("0")
else:
    print((x[1] - x[0]) * (y[1] - y[0]))

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 _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        min_x = max(min_x, x)
    elif a == 2:
        max_x = min(max_x, x)
    elif a == 3:
        min_y = max(min_y, y)
    else:
        max_y = min(max_y, y)

if max_x > min_x and max_y > min_y:
    print(max(0, (max_x - min_x) * (max_y - min_y)))
else:
    print(0)

Submission status: Accepted

Solution code:
nim,mike,kite=map(int,input().split())
x1=0
y1=0
x2=nim
y2=mike
for i in range(kite):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x1,x)
    elif a==2:
        x2=min(x2,x)
    elif a==3:
        y1=max(y1,y)
    elif a==4:
        y2=min(y2,y)
print(max(0,(x2-x1))*max(0,(y2-y1)))

Submission status: Accepted

Solution code:
w, h, n = [int(x) for x in input().split()]
S = [0,w,0,h]

for i in range(n):
    x, y, a = [int(_) for _ in input().split()]

    if a == 1:
        S[0] = max(S[0], x)        
    if a == 2:
        S[1] = min(S[1], x)
    if a == 3:
        S[2] = max(S[2], y)        
    if a == 4:
        S[3] = min(S[3], y)

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

Submission status: Accepted

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

S = W*H
h = list(range(1, H+1))
w = list(range(1, W+1))
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        w = list(filter(lambda num: num > x, w))
    elif a == 2:
        w = list(filter(lambda num: num <= x, w))
    elif a == 3:
        h = list(filter(lambda num: num > y, h))
    else:
        h = list(filter(lambda num: num <= y, h))

print(len(w)*len(h))

Submission status: Accepted

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

grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

left = 0
right = W
up = H
down = 0

for i in range(N):
  if grid[i][2] == 1:
    left = max(left,grid[i][0])
  elif grid[i][2] == 2:
    right = min(right,grid[i][0])
  elif grid[i][2] == 3:
    down = max(down,grid[i][1])
  elif grid[i][2] == 4:
    up = min(up,grid[i][1])
  
if (right>left)and(up>down):
  print((right-left)*(up-down))
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
w = 0
h = 0
lx = list()
ly = list()
la = list()
for i in range(1, N+1):
    X, Y, A = map(int, input().split())
    lx.append(X)
    ly.append(Y)
    la.append(A)
    if A == 1 and w < X:
        w = X
    elif A == 2 and X < W:
        W = X
    elif A == 3 and h < Y:
        h = Y
    elif A == 4 and Y < H:
        H = Y
S = (W - w)*(H - h)
if H < h or W < w:
    S = 0
print(S)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
wmax=w
wmin=0
hmax=h
hmin=0

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if wmin<=x:
            wmin=x
    elif a==2:
        if wmax>=x:
            wmax=x
    elif a==3:
        if hmin<=y:
            hmin=y
    else:
        if hmax>=y:
            hmax=y
if wmax>wmin and hmax>hmin:
    print((wmax-wmin)*(hmax-hmin) )
else:
    print(0)

Submission status: Accepted

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

for _ in range(N):
    xi, yi, a = map(int, input().split())
    if a == 1:
        x0 = max(xi, x0)
    elif a == 2:
        W = min(xi, W)
    elif a == 3:
        y0 = max(yi, y0)
    elif a == 4:
        H = min(yi, H)

ans = (W-x0)*(H-y0)
print(ans if x0 < W and y0 < H else 0)

Submission status: Accepted

Solution code:
import numpy as np
def I(): return map(int,input().split())

w, h, n = I()
m = np.zeros((h, w), int)

while n:
    x, y, a = I()

    start = y * (a == 4)             # a = 4 のときのみy それ以外は0
    end = y if (a == 3) else h       # a = 3 のときのみy それ以外はh

    begin = x * (a == 2)             # a = 2 のときのみx それ以外は0
    finish = x if (a == 1) else w    # a = 1 のときのみx それ以外はw

    m[start:end, begin:finish] = 1
    n -= 1
print(h * w - m.sum())

Submission status: Accepted

Solution code:
x_max, y_max, N = map(int, input().split())
x_min, y_min = 0, 0
l = [[int(i) for i in input().split()] for _ in range(N)]
for i in range(N):
  if l[i][2] == 1:
    x_min = max(x_min, l[i][0])
  elif l[i][2] == 2:
    x_max = min(x_max, l[i][0])
  elif l[i][2] == 3:
    y_min = max(y_min, l[i][1])
  elif l[i][2] == 4:
    y_max = min(y_max, l[i][1])
if x_max-x_min > 0 and y_max-y_min:
  print((x_max-x_min)*(y_max-y_min))
else:
  print(0)

Submission status: Accepted

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

min_x = 0
max_x = W
min_y = 0
max_y = H
for x, y, a in query:
    if a == 1:
        min_x = max(min_x, x)
    elif a == 2:
        max_x = min(max_x, x)
    elif a == 3:
        min_y = max(min_y, y)
    else:
        max_y = min(max_y, y)

print(max(0, (max_x - min_x)) * max(0, (max_y - min_y)))

Submission status: Accepted

Solution code:
W, H, N = list(map(int, input().split()))
floor = [[0 for row in range(W)] for col in range(H)]
for i in range(N):
  x, y, a = list(map(int, input().split()))
  if a == 1:
    for row in floor:
      for i in range(len(row[:x])):
        row[i] = 1
  elif a == 2:
    for row in floor:
      for i in range(len(row[x:])+x)[x:]:
        row[i] = 1
  elif a == 3:
    for (h, row) in enumerate(floor):
      if H-y < h+1:
        for i in range(len(row)):
          row[i] = 1
  elif a == 4:
    for (h, row) in enumerate(floor):
      if h < H-y:
        for i in range(len(row)):
          row[i] = 1
res = 0
for row in floor:
  res += row.count(0)
print(res)

Submission status: Accepted

Solution code:
# import fractions
# import sys
from sys import stdin

w, h, n = map(int, stdin.readline().rstrip().split())

data = [list(map(int, stdin.readline().rstrip().split())) for i in range(n)]

l, r = 0, w
d, u = 0, h
for di in data:
    if di[2] == 1:
        if l < di[0]:
            l = di[0]
    elif di[2] == 2:
        if r > di[0]:
            r = di[0]
    elif di[2] == 3:
        if d < di[1]:
            d = di[1]
    else:
        if u > di[1]:
            u = di[1]


if (r - l) <= 0 or (u - d) <= 0:
    print(0)
else:
    print((r - l)*(u - d))

Submission status: Accepted

Solution code:
import numpy as np


w, h, n = map(int, input().split())
v = np.zeros((h, w), dtype=np.int)
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        v[:, :x] = 1
    elif a == 2:
        v[:, x:] = 1
    elif a == 3:
        v[:y, :] = 1
    else:
        v[y:, :] = 1
print(w*h-np.sum(v))

Submission status: Accepted

Solution code:
def main():
    W, H, N = map(int, input().split())
    area = [[0 for w in range(W)] for h in range(H) ]

    for n in range(N):
        x, y, a = map(int, input().split())
        
        if a == 1 :
            for i in range(H):
                for j in range(x):
                    area[i][j] = 1
        elif a == 2:
            for i in range(H):
                for j in range(x, W):
                    area[i][j] = 1
        elif a == 3:
            for i in range(H - y, H):
                for j in range(W):
                    area[i][j] = 1
        elif a == 4:
            for i in range(H - y):
                for j in range(W):
                    area[i][j] = 1
    count = 0
    
    for i in range(H):
        for j in range(W):
            if area[i][j] == 0:
                count += 1
    print(count)

main()

Submission status: Accepted

Solution code:
def main():
    W, H, N = map(int, input().split())
    area = [[0 for w in range(W)] for h in range(H) ]

    for n in range(N):
        x, y, a = map(int, input().split())
        
        if a == 1 :
            for i in range(H):
                for j in range(x):
                    area[i][j] = 1
            # dump(area, H, W)
                    
        elif a == 2:
            for i in range(H):
                for j in range(x, W):
                    area[i][j] = 1
            # dump(area, H, W)

        elif a == 3:
            for i in range(H - y, H):
                for j in range(W):
                    area[i][j] = 1
            # dump(area, H, W)
            
        elif a == 4:
            for i in range(H - y):
                for j in range(W):
                    area[i][j] = 1
            # dump(area, H, W)
    count = 0

    for i in range(H):
        for j in range(W):
            if area[i][j] == 0:
                count += 1
    print(count)

def dump(area, H, W):
    for i in range(H):
        for j in range(W):
            print(str(area[i][j]) + " ", end="")
        print()

main()

Submission status: Accepted

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

a1, a2, a3, a4 = [], [], [], []

for i in range(N):
  if li[i][2] == 1:
    a1.append(li[i])
  elif li[i][2] == 2:
    a2.append(li[i])
  elif li[i][2] == 3:
    a3.append(li[i])
  elif li[i][2] == 4:
    a4.append(li[i])

a1XMAX, a2Xmin, a3YMAX, a4Ymin = 0, W, 0, H
    
if a1 == []:
  pass
else:
  for i in range(len(a1)):
    a1XMAX = max(a1[i][0], a1XMAX)

if a2 == []:
  pass
else:
  for i in range(len(a2)):
    a2Xmin = min(a2[i][0], a2Xmin)
    
if a3 == []:
  pass
else:
  for i in range(len(a3)):
    a3YMAX = max(a3[i][1], a3YMAX)

if a4 == []:
  pass
else:
  for i in range(len(a4)):
    a4Ymin = min(a4[i][1], a4Ymin)

if a1XMAX >= a2Xmin or a3YMAX >= a4Ymin:
  result = 0
  print(result)
  exit()
else:
  result = (a2Xmin - a1XMAX) * (a4Ymin - a3YMAX)
  print(result)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
rect = [[1 for _ in range(w)] for _ in range(h)]
def drawx(x, y):
    for i in range(x):
        for j in range(y):
            rect[j][i] = 0

def drawy(x, y):
    for i in range(x, w):
        for j in range(y, h):
            rect[j][i] = 0

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        drawx(x, h)
    elif a == 2:
        drawy(x, 0)
    elif a == 3:
        drawx(w, y)
    else:
        drawy(0, y)
print(sum(sum(rect, [])))

Submission status: Accepted

Solution code:
def solve():
    W, H, N = map(int,input().split())
    area = [[True] * W for i in range(H)]
    for i in range(N):
        x,y,a = map(int,input().split())
        x -= 1
        y -= 1

        if a == 1:
            for h in range(H):
                for w in range(W):
                    if w > x:
                        continue
                    area[h][w] = False
        elif a == 2:
            for h in range(H):
                for w in range(W):
                    if w <= x:
                        continue
                    area[h][w] = False
        elif a == 3:
            for h in range(H):
                if h > y:
                    continue
                for w in range(W):
                    area[h][w] = False
        else:
            for h in range(H):
                if h <= y:
                    continue
                for w in range(W):
                    area[h][w] = False
        

    cnt = 0
    for h in range(H):
        for w in range(W):
            if area[h][w]:
                cnt += 1
    print(cnt)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

for _ in range(N):
    xi, yi, a = map(int, input().split())
    if a == 1:
        x0 = max(xi, x0)
    elif a == 2:
        W = min(xi, W)
    elif a == 3:
        y0 = max(yi, y0)
    elif a == 4:
        H = min(yi, H)

ans = (W-x0)*(H-y0)
# if ans < 0:
#     ans = 0
# print(ans)
print(ans if x0 < W and y0 < H else 0)

Submission status: Accepted

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

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

for i in range(n):
  x, y, a = map(int, input().split())
  x -= 1
  y -= 1
  if a==1:
    for ii in range(h):
      for jj in range(w):
        if jj<=x:
          m[ii][jj] = 1
  if a==2:
    for ii in range(h):
      for jj in range(w):
        if jj>x:
          m[ii][jj] = 1
  if a==3:
    for ii in range(h):
      for jj in range(w):
        if ii<=y:
          m[ii][jj] = 1
  if a==4:
    for ii in range(h):
      for jj in range(w):
        if ii>y:
          m[ii][jj] = 1
          
cum = sum([sum(m[i]) for i in range(h)])
#[print(*m[i]) for i in range(h)]
print(h*w-cum)

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
xika=[0]
xijo=[w]
yika=[0]
yijo=[h]
x = 0
for x in range (n):
    listA = list(map(int,input().split()))
    if listA[2] == 1:
        xika.append(listA[0])
    elif listA[2] == 2:
        xijo.append(listA[0])
    elif listA[2] == 3:
        yika.append(listA[1])
    else:
        yijo.append(listA[1])
    x += 1
xika.sort()
xijo.sort()
yika.sort()
yijo.sort()
if xika[-1]>xijo[0] or yika[-1]>yijo[0]:
    print(0)
else:
    print((xijo[0]-xika[-1])*(yijo[0]-yika[-1]))