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:
w, h, n = map(int, input().split(" "))
grouped_dots = {1: [], 2: [], 3: [], 4: []}

dots = []
for _ in range(n):
  dots.append(list(map(int, input().split(" "))))

for dot in dots:
  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])
x_max = min(grouped_dots[2])
y_min = max(grouped_dots[3])
y_max = min(grouped_dots[4])
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)

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split(" "))
grouped_dots = {1: [], 2: [], 3: [], 4: []}
for _ in range(n):
  dot = 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])
x_max = min(grouped_dots[2])
y_min = max(grouped_dots[3])
y_max = min(grouped_dots[4])
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)

Submission status: Runtime Error

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


grouped_dots = {1: [], 2: [], 3: [], 4: []}
for _ in range(n):
  dot = list(map(int, input().split(" ")))
  print(dot)
  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])
x_max = min(grouped_dots[2])
y_min = max(grouped_dots[3])
y_max = min(grouped_dots[4])
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)

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split(" "))
grouped_dots = {1: [], 2: [], 3: [], 4: []}
for _ in range(n):
  dot = list(map(int, input().split(" ")))
  print(dot)
  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])
x_max = min(grouped_dots[2])
y_min = max(grouped_dots[3])
y_max = min(grouped_dots[4])
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)

Submission status: Runtime Error

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

for i in lis:
  if i[2] == 1:
    if x < i[0]:
      x=i[0]
  elif i[2] == 2:
    if i[0] < w:
      w=i[0]
  elif i[2] == 3:
    if y < i[1]:
      y=i[1]
  else:
    if i[1] < h:
      h=i[1]
x_a = w-x
y_a= h-y
if x_a < 0 or y_a < 0:
  print(0)
  exit()
print(x_a*y_a)
    if i[1] < y:
      h=i[1]
x_a = w-x
y_a= h-y
if x_a < 0 or y_a < 0:
  print(0)
  exit()
print(x_a*y_a)

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
w1=0
w2=w
h1=0
h2=h
for i in range(n):
    a,b,c=map(int,input().split())
    if c==1:
        w1=a
    elif c==2:
        w2=a
    elif c==3:
        h1=b
    elif c==4:
        h2=b
if w2<=w1 or h2<=h1:
    print(0)
else:
    print(max(0,(w2-w1)*(h2-h1))

Submission status: Runtime Error

Solution code:
W, H, N = list(map(int, input().split()))
A = []
for _ in range(N):
  A.append(list(map(int, input().split())))
  
xmax, xmin, ymax, ymin = W, 0, H, 0
for a in A:
  if a[2] == 1:
    xmin = max(xmin, a[0])
  if a[2] == 2:
    xmax = min(xmax, a[0])
  if a[2] == 3:
    ymin = max(ymin, a[1])
  if a[2] == 4:
    ymax = min(ymax, a[1])D
    
S = (xmax-xmin) * (ymax-ymin)
if S < 0:
  S = 0
print(S)

Submission status: Runtime Error

Solution code:
w,h,n=MI()
rect=[0,w,0,h]
for i in range(n):
    a,b,c=MI()
    if c<=2:
        rect[c-1]=a
    else:
        rect[c-1]=b
#print(rect)
print(max(0,rect[3]-rect[2])*max(0,rect[1]-rect[0]))

Submission status: Runtime Error

Solution code:
W,H,N = int(input())
p = 0
q = W
l = 0
m = H

for i in range(N):
  x,y,a = map(int.split())
  if a == 1:
    p = max(p,x)
  if a == 2:
    q = min(q,x)
  if a == 3:
    l = max(l,y)
  if a == 4:
    m = min(m,y)
S = (q-p)*(m-l)
print(S)

Submission status: Runtime Error

Solution code:
W,H,N = int(input())
p = 0
q = W
l = 0
m = H

for i in range(N):
  x,y,a = map(int.split())
  if a == 1:
    p = max(p,x)
  if a == 2:
    q = min(q,x)
  if a == 3:
    l = max(l,y)
  if a == 4:
    m = min(m,x)
S = (q-p)*(l-m)
print(S)

Submission status: Runtime Error

Solution code:
W, H, N = map(int,input().split())
p = 0
q = W
r = 0
s = H
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        if x > p:
            p = x
    if a == 2:
        if x < q:
            q = x
    if a == 3:
        if y > r:
            r = y
    if a == 4:
        if y < s:
            s = y
ans = (q-p)*(s-r)
if ans < 0
    ans = 0
print(ans)

Submission status: Runtime Error

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(result)
else:
    print(0)

Submission status: Runtime Error

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 row in r:
				row[:ix] = [False]*ix
		elif a == 2:
			for row in r:
				row[ix:] = [False]*ix if ix > 0 else [False]*w
		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: Runtime Error

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 row in r:
				row[:ix] = [False]*ix
		elif a == 2:
			for row in r:
				row[ix:] = [False]*ix
		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: Runtime Error

Solution code:
w,h,n=map(int,input().split())
s=w*h
while n>0:
    x,y,a=map(int,input().split())
    if

Submission status: Runtime Error

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

Wmin = 0
Wmax = W
Hmin = 0
Hmax = H

for i in range(N):
    x, y, z = map(int,input().split())
    if z == 1:
        Wmin = x
    if z == 2:
        Wmax = x
    if z == 3:
        Hmin = y
    if z == 4:
        Hmax = y

print(min((Wmax-Wmin)*(Hmax-Hmin)), 0)

Submission status: Runtime Error

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

g = [1*h]*w

for i in range(n):
  if a[i][2] == 1:
    g[:a[i][0]] = [0]*a[i][0]
  elif a[i][2] == 2:
    g[a[i][0]:] = [0]*a[i][0]
  elif a[i][2] == 3:
    g = [0 if g[j] == 0 else g[j]-a[i][1] for j in range(w)]
  elif a[i][2] == 4:
    g = [0 if g[j] == 0 else a[i][1] for j in range(w)]
    
  
print(sum(g))

Submission status: Runtime Error

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

x = [int(i) for i in range(w+1)]
y = [int(i) for i in range(h+1)]

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

print((max(x)-min(x)) * (max(y)-min(y)))

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
w1=w
h1=h
for i in range(n):
    if xya[i][2]==1:w1=w-int(xya[i][0])
    elif xya[i][2]==2:w1-=(w-int(xya[i][0])
    elif xya[i][2]==3:h1=h-int(xya[i][1])
    elif xya[i][2]==4:h1-=(h-int(xya)[i][1])
    else:pass
if w1>0 and h1>0:print(w1*h1)
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)]
xya.sort(a)
w1=w
h1=h
for i in range(n):
    if xya[i][2]==1:w1=w-int(xya[i][0])
    elif xya[i][2]==2:w1-=(w-int(xya[i][0])
    elif xya[i][2]==3:h1=h-int(xya[i][1])
    elif xya[i][2]==4:h1-=(h-int(xya)[i][1])
    else:pass
if w1>0 and h1>0:print(w1*h1)
else:print(0)

Submission status: Runtime Error

Solution code:
import numpy as np
w,h,n = map(int,input().split())
d = np.zeros(w-1,h-1)
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        d[:w] = 1
    elif a == 2:
        d[w:] = 1
    elif a ==3:
        d[:,:h] = 1
    else:
        d[:,h:] = 1
print(np.count_nonzero(d==0))

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
  elif a==2:
    l[:,x:] = 1
  elif a==3:
    l[:y,:] = 1
  elif a==4:
    l[y:,:] = 1
    
print(H*W-int(l.sum().sum()))

Submission status: Runtime Error

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

#座標を作る
right = w
left = 0
upper = h
under = 0

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

    if a ==1:
        left = max(x,left)
    elif a ==2:
        right = min (x,right)
    elif a ==3:
        under = max(y,under)
    elif a ==4:
        upper = min(y,upper)

if　(upper-under)>0 and (right-left)>0:
    c = (upper-under)*(right-left)
    print(c)
else:
    print(0)

Submission status: Runtime Error

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

#座標を作る
right = w
left = 0
upper = h
under = 0

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

if a ==1:
    left = max(x,left)
elif a ==2:
    right = min (x,right)
elif a ==3:
    under = max(y,under)
elif a ==4:
    upper = min(y,upper)

if　(upper-under)>0 and (right-left)>0:
    c = (upper-under)*(right-left)
    print(c)
else:
    print(0)

Submission status: Runtime Error

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

xr = w
xl = 0
yu = h
yl = 0

for i in range(n):
    if T[i][2] == 2:
        xr = min(xr, T[i][0])
    elif T[i][2] == 1:
        xl = max(xl, T[i][0])
    elif T[i][2] == 4:
        yu = min(yu, T[i][1])
    else:
        yl = max(yl, T[i][1])

print(max((xr - xl) * (yu - yl), 0)

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

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

Submission status: Runtime Error

Solution code:
x,y=0,0
for s,t,u in a:
    if u==1:
        x=max(x,s)
    elif u==2:
        w=min(w,s)
    elif u==3:
        y=max(y,t)
    else:
        h=min(h,t)
height=max(0,h-y)
width=max(0,w-x)
print(height*width)

Submission status: Runtime Error

Solution code:
w, h, n = [int(i) for i in input().split()]
w2, h2 = w, h
wb, hb = [False] * w, [False] * h
for i in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1 and not wb[x]:
        w2 -= x
        wb[x] = True
    elif a == 2 and not wb[x]:
        w2 -= w - x
        wb[x] = True
    elif a == 3 and not hb[y]:
        h2 -= y
        hb[y] = True
    elif a == 4 and not hb[y]:
        h2 -= h - y
        hb[y] = True
ans = w2 * h2
print(ans if ans > 0 else 0)

Submission status: Runtime Error

Solution code:
W,H,N = map(int,input().split())
c = [0]*N
max_x,min_x = 0,W
max_y,min_y = 0,H
for _ in range(M):
  x,y,a = map(int,input().split())
  if a == 1:
    max_x = max(max_x,x)
  elif a == 2:
    min_x = min(min_x,x)
  elif a == 3:
    max_y = max(max_y,y)
  else:
    min_y = min(min_y,y)
  if min_x <= max_x or min_y <= max_y:
      print(0)
      exit()
print((min_x-max_x)*(min_y-max_y))

Submission status: Runtime Error

Solution code:
W,H,N=map(int,input().split())
x=[0]*N
y=[0]*N
a=[0]*N
minX=0
maxX=W
minY=0
maxY=H
for i in range(N):
  x[i],y[i],a[i]=map(int,input().split())
  if a[i]==1:
    minX=max(minX,x[i])
  if a[i]==2:
    maxX=min(maxX,x[i]) 
  if a[i]==3:
    minY=max(minY,y[i])
  if a[i]==4:
    maxY=min(maxY,y[i]) 

ans=(maxX-minX)*(maxY-minY)
if maxX<minX or maxY<minY:
  ans=0
print(max(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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())
    
total = W*H

x_list = np.arange(0, W+1)
y_list = np.arange(0, H+1)
for i in range(len(a)):
    if a[i] == 1:
        x_list = x_list[x[i]:]
    elif a[i] == 2:
        x_list = x_list[:x[i]+1]
    elif a[i] == 3:
        y_list = y_list[y[i]:]
    else:
        y_list = y_list[:y[i]+1]
        
x_len = x_list[-1]-x_list[0]
y_len = y_list[-1]-y_list[0]

print(x_len*y_len)

Submission status: Runtime Error

Solution code:
import numpy as np

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

ze = np.ones(W+1, H+1)
for i in range(N):
    x, y, a = map(int, input().split())
    
    if a == 1:
        ze[:x, :] = 0
    elif a == 2:
        ze[x+1:, :] = 0
    elif a == 3:
        ze[:, :y] = 0
    elif a == 4:
        ze[:, y+1:] = 0

print(np.sum(ze))

Submission status: Runtime Error

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

for Nimport numpy as np

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

ze = np.ones(W+1, H+1)
for i in range(N):
    li = [x, y, a = map(int, input().split()) for i in range(N)]
    
    if a == 1:
        ze[:x, :] = 0
    elif a == 2:
        ze[x+1:, :] = 0
    elif a == 3:
        ze[:, :y] = 0
    elif a == 4:
        ze[:, y+1:] = 0

print(np.sum(ze))

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

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

    if a == 1:
        min_W = x
    elif a == 2:
        max_W = x
    elif a == 3:
        min_H = y
    else:
        max_H = y

print(max(((max_H - min_H) * (max_W - min_W)), 0)

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

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

a1 = [0,0]
a2 = [W,0]
a3 = [0,0]
a4 = [0,H]

for i in range(0,N):
  lst = [int(i) for i in input().split(" ")]
  if lst[2] == 1:
    a1[0] = max(a1[0],lst[0])
  elif lst[2] == 2:
    a2[0] = max(a2[0],lst[0])
  elif lst[2] == 3:
    a3[1] = max(a3[1],lst[1])
  elif lst[2] == 4:
    a4[1] = max(a4[1],lst[1])

print(max(0,a2[0]-a1[0])*max(0,(a4[1]-a3[1]))

Submission status: Runtime Error

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

a1 = [0,0]
a2 = [W,0]
a3 = [0,0]
a4 = [0,H]

for i in range(0,N):
  lst = [int(i) for i in input().split(" ")]
  if lst[2] == 1:
    a1[0] = max(a1[0],lst[0])
  elif lst[2] == 2:
    a2[0] = max(a2[0],lst[0])
  elif lst[2] == 3:
    a3[1] = max(a3[1],lst[1])
  elif lst[2] == 4:
    a4[1] = max(a4[1]1,lst[1])

print(max(0,a2[0]-a1[0])*max(0,(a4[1]-a3[1]))

Submission status: Runtime Error

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

a1 = [0,0]
a2 = [W,0]
a3 = [0,0]
a4 = [0,H]

for i in range(0,N):
  lst = [int(i) for i in input().split(" ")]
  if lst[2] == 1:
    a1[0] = max(a1[0],lst[0])
  elif lst[2] == 2:
    a2[0] = max(a2[0],lst[0])
  elif lst[2] == 3:
    a3[1] = max(a3[1],lst[1])
  elif lst[2] == 4:
    a4[1] = max(a4[]1,lst[1])

print(max(0,a2[0]-a1[0])*max(0,(a4[1]-a3[1]))

Submission status: Runtime Error

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

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

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and left <= x:
        left = x
    elif a == 2 and right >= x:
        right = x
    elif a == 3 and bottom <= y:
        bottom = y
    elif a == 4 and top >= y:
        top = y

if (top-bottom)*(right-left) > 0 and (top-bottom)>0 and (rightt-left)>0:
    print((top-bottom)*(right-left))
else:
    print(0)

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for i in range(n)]
xya1=[i[0] for i in xya if i[2]==1]
xya2=[i[0] for i in xya if i[2]==2]
xya3=[i[1] for i in xya if i[2]==3]
xya4=[i[1] for i in xya if i[2]==4]
left=max(xya1)
right=min(xya2)
lower=max(xya3)
upper=min(xya4)
if left>=right or lower>=upper:
  print(0)
else:
  print((right-left)*(upper-lower))

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for i in range(n)]
xya1=[i[0] for i in xya if i[2]==1]
xya2=[i[0] for i in xya if i[2]==2]
xya3=[i[1] for i in xya if i[2]==3]
xya4=[i[1] for i in xya if i[2]==4]
left=max(xya1)
right=min(xya2)
lower=max(xyz3)
upper=min(xyz4)
if left>=right or lower>=upper:
  print(0)
else:
  print((right-left)*(upper-lower))

Submission status: Runtime Error

Solution code:
 import math
import sys
import numpy as np

#n, a, b= map(int, input().split())
w, h, n  = map(int, input().split())
#s = list(str(input()))
#n = int(input())
#a = list(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())
area = np.ones([w,h])

for i in range(n):
  if(a[i] == 1):
    area[:x[i],:] = 0
  if(a[i] == 2):
    area[w-x[i]-1:w,:] = 0
  if(a[i] == 3):
    area[:,:y[i]] = 0
  if(a[i] == 4):
    area[:,h-y[i]-1] = 0

print(np.count_nonzero(area == 1))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

w1 = 0
w2 = w
h1 = 0
h2 = h

for i in range(n):
    if(mat[i][2] == 1 and w1 < mat[i][0]):
        w1 = mat[i][0]
    elif(mat[i][2] == 2 and w2 > mat[i][0]):
        w2 = mat[i][0]
    elif(mat[i][2] == 3 and w3 < mat[i][1]):
        h1 = mat[i][1]
    elif(mat[i][2] == 4 and w4 > mat[i][1]):
        h2 = mat[i][1]
        
print((w2-w1)*(h2-h1) if w2 >= w1 and h2 >= h1 else 0)

Submission status: Runtime Error

Solution code:
#abc047-b
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#x,y,a
x_min=0
y_min=0

for i in l:
    if i[-1]==1:
        x_min=max(i[0],x_min)

    elif i[-1]==2:
        w=min(i[0],w)

    elif i[-1]==3:
        y_min=max(i[1],y_min)

    else:
        h=min(i[1],h)
s=
print((w-x_min)*(h-y_min) if (w-x_min)>0 and (h-y_min)>0 else 0)

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
paint_dot = {}
for _ in range(N):
  t1, t2, t3 = map(int,input().split())
  paint_dot[(t1, t2)] = t3

pattern_H = [1]*H
pattern_W = [1]*W

for key in paint_dot:
  if paint_dot[key] == 1:
    for i in range(key[0]):
      pattern_W[i] = 0
  elif paint_dot[key] == 2:
    for i in range(key[0],W):
      pattern_W[i] = 0
  elif paint_dot[key] == 3:
    for i in range(key[1]):
      pattern_H[i] = 0
  else:
    for i in range(key[1],W):
      pattern_H[i] = 0

print(sum(pattern_W) * sum(pattern_H))

Submission status: Runtime Error

Solution code:
xmax,ymax,N = [int(i) for i in input().split()]
x,y,a = list(map(int,input().split()))
xmin = 0
ymin = 0

for i in range(N):
    if a[i] == 1:
        if xmin < x[i]:
            xmin = x[i]
    elif a[i] == 2:
        if xmax > x[i]:
            xmax = x[i]
    elif a[i] == 3:
        if ymin < y[i]:
            ymin = y[i]
    elif a[i] == 4:
        if ymax > y[i]:
            ymax = y[i]

if ymax > ymin and xmax > xmin:
    print((ymax - ymin)*(xmax - xmin))
else:
    print(0)

Submission status: Runtime Error

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

## 長方形のマスを塗りつぶしていって残ったマス目を数えるイメージ
# 0: 白, 1: 黒
square = []
for i in range(H):
    horizonatlArea = []
    for j in range(W):
        horizonatlArea.append(0)
    square.append(horizonatlArea)

# Aの要素の番号に応じてsquareに1を埋めていく
for n in range(N):
    if A[n] == 1:
        for i in range(X[n]):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 2:
        for i in range(X[n], W):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 3:
        for i in range(W):
            for j in range(y[n]):
                square[j][i] = 1
    elif A[n] == 4:
        for i in range(W):
            for j in range(Y[n], H):
                square[j][i] = 1

# square内の要素の数を数えて出力
cnt = 0
for j in range(H):
    cnt += square[j].count(0)

print(cnt)

Submission status: Runtime Error

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

## 長方形のマスを塗りつぶしていって残ったマス目を数えるイメージ
# 0: 白, 1: 黒
square = []
for i in range(H):
    horizonatlArea = []
    for j in range(W):
        horizonatlArea.append(0)
    square.append(horizonatlArea)

# Aの要素の番号に応じてsquareに1を埋めていく
for n in range(N):
    if A[n] == 1:
        for i in range(X[n]):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 2:
        for i in range(X[n], W):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 3:
        for i in range(W):
            for j in range(y[n]):
                square[j][i] = 1
    elif A[n] == 4:
        for i in range(W):
            for j in range(Y[n], H):
                square[j][i] = 1
print(square)

# square内の要素の数を数えて出力
cnt = 0
for j in range(H):
    cnt += square[j].count(0)

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

points = [list(map(int, input().split())) for _ in range(N)]
# res = [[0 for _ in range(W)] for _ in range(H)]
res = 0

minx, maxx, miny, maxy = [0,W,0,H]
x = 0
y = 0

for x,y,a in points:
    if a == 1:
        minx = x
    if a == 2:
        maxx = x
    if a == 3:
        miny = y
    if a == 4:
        maxy = y


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

print(res)
~

Submission status: Runtime Error

Solution code:
import sys
w,h,n = map(int, sys.stdin.readline().split())

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

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

print(x_min, x_max, y_min, y_max)
if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;
const int mod = 1e9+7;
int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int lcs(string a, string b) {
  int n = a.size(), m = b.size();
  int dp[2][m+1];
  for(int i = 0;i <= n;i++) {
    for(int j = 0;j <= m;j++) {
      if(i==0||j==0) dp[i%2][j] = 0;
      else {
        if(a[i-1] == b[j-1]) dp[i%2][j] = 1 + dp[1-i%2][j-1];
        else dp[i%2][j] = max(dp[i%2][j-1], dp[1-i%2][j]);
      }
    }
  }
  return dp[n%2][m];
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

bool equal(string s) {
  for(int i = 0,j = s.size()/2;j < s.size();i++,j++) {
    if(s[i] != s[j]) return false;
  }
  return true;
}

ll fact(int n) {
  ll ans = 1;
  fr(i,2,n+1) ans = (ans*i)%mod;
  return ans;
}

ull f(ll a, ll x) {
  if(a < 0) return 0;
  return (a/x+1);
}

int main() {
  int w,h,n;
  cin>>w>>h>>n;
  int minx = 0, maxx = w, miny = 0, maxy = h; // white area
  while(n--) {
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1) {
      minx = max(minx, x);
    }else if(a==2) {
      maxx = min(maxx, x);
    }else if(a==3) {
      miny = max(miny,y);
    }else if(a==4){
      maxy = min(maxy,y);
    }
  }
  int ans = max(0,(maxx-minx)*(maxy-miny));
  cout<<ans;
}

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(N)]
x_black = [0] * W 
y_black = [0] * H 
def get_area(x, y, a): 
        if a == 1:
                x_black[:x] = [1] * x 
        if a == 2:
                x_black[x:W] = [1] * (W - x)
        if a == 3:
                y_black[y] = [1] * y 
        if a == 4:
                y_black[y:H] = [1] * (H - y)
for i in xy: 
        get_area(i[0], i[1], i[2])
print(x_black.count(0) * y_black.count(0))

Submission status: Runtime Error

Solution code:



def main()->None:
    W, H, N = map(int, input().split())
    range_N = range(N)
    xl, xr, yd, yu = 0, w, 0, h
    for i in range_N:
        x, y, a = map(int, input().split())
        if a == 1:
            xl = max(x, xl)
        if a == 2:
            xr = min(x, xr)
        if a == 3:
            yd = max(y, yd)
        else:
            yu = min(y, yu)
    if xl >= xr or yd >= yu:
        print(0)
    else:
        print((xr - xl) * (yu - yd))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:



def main()->None:
    W, H, N = map(int, input().split())
    range_N = range(N)
    xl, xr, yd, yu = 0, w, 0, h
    for i in range_N:
        x, y, a = map(int, input().split()
        if a == 1:
            xl = max(x, xl)
        if a == 2:
            xr = min(x, xr)
        if a == 3:
            yd = max(y, yd)
        else:
            yu = min(y, yu)
    if xl >= xr or yd >= yu:
        print(0)
    else:
        print((xr - xl) * (yu - yd))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:



def main()->None:
    W, H, N = map(int, input().split())
    range_N = range(N)
    xy = []
    a_i = []
    for i in range_N:
        x, y, a = map(int, input().split())
        xy.append([x, y])
        a_i.append(a)
    
    flag = False
    for x, y, a in zip(xy, a_i):
        if a % 4 == 1:
            W -= x
        if a % 4 == 2:
            W -= x
        if a % 4 == 3:
            H -= y
        else:
            H -= y
        if W <= 0 or H <= 0:
            flag = True
            break
    if flag: print(0)
    else: print(W*H)



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
W,H,N = map(int,input().split())
zero = [0,0]
X = [W,H]
ans = True
for i in range(N):
    x,y,a = map(int,input().split())
    if(a == 1):
        if zero[0] < x < X[0]:
            zero[0] = x
        elif X[0] =< x:
            ans = False
            break
    elif(a == 2):
        if zero[0] < x < X[0]:
            X[0] = x
        elif zero[0] => x:
            ans = False
            break
    elif(a == 3):
        if zero[1] < y < X[1]:
            zero[1] = y
        elif X[1] =< y:
            ans = False
            break
    elif(a == 4):
        if zero[1] < y < X[1]:
            X[1] = y
        elif zero[0] => y:
            ans = False
            break
if(ans):
    S = (X[1] - zero[1]) * (X[0] - zero[0])
    print(S)
else:
    print(0)

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
maxX,minX,maxY,minY = W, 0, H ,0
for i in range(N):
    x, y, a = map(int, input().split())
    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
        
xl = maxX - minX
yl = maxY - minY
if x1 > 0 and y1 > 0:
    print(x1*y1)
else:
    print(0)