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: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
s = [[1]*w]*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):
                s[j][k] = 0
    elif a == 2:
        for j in range(h):
            for k in range(x+1,w):
                s[j][k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(w):
                s[j][k] = 0
    elif a == 4:
        for j in range(y+1,h):
            for k in range(w):
                s[j][k] = 0
c = 0
for i in range(h):
    c += sum(s[i])
print(c)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
s = [[1]*w]*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):
                s[j][k] = 0
    elif a == 2:
        for j in range(h):
            for k in range(x):
                s[j][-1-k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(w):
                s[j][k] = 0
    elif a == 4:
        for j in range(y):
            for k in range(w):
                s[-1-j][k] = 0
c = 0
for i in range(h):
    c += sum(s[i])
print(c)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
for i in range(N):
    if x_max <= x_min or y_max <= y_min:
        print(0)
        break
    elif a[i] == 1:
        if x_min < x[i]:
            x_min = x[i]
    elif a[i] == 2:
        if x_max > x[i]:
            x_max = x[i]
    elif a[i] == 3:
        if y_min < y[i]:
            y_min = y[i]
    elif a[i] == 4:
        if y_max > y[i]:
            y_max = y[i]
print((x_max - x_min)*(y_max - y_min))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
for i in range(N):
    if x_max <= x_min or y_max <= y_min:
        print(0)
        break
    elif a[i] == 1:
        if x_min < x[i]:
            x_min = x[i]
    elif a[i] == 2:
        if x_max < x[i]:
            x_max = x[i]
    elif a[i] == 3:
        if y_min < x[i]:
            y_min = y[i]
    elif a[i] == 4:
        if y_max < x[i]:
            y_max = y[i]
print((x_max - x_min)*(y_max - y_min))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
for i in range(N):
    if x_max <= x_min or y_max <= y_min:
        print(0)
        break
    elif a[i] == 1:
        x_min = x[i]
    elif a[i] == 2:
        x_max = x[i]
    elif a[i] == 3:
        y_min = y[i]
    elif a[i] == 4:
        y_max = y[i]
print((x_max - x_min)*(y_max - y_min))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
x_min = 0
x_max =  W
y_min = 0
y_max = H
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
    if a[i] == 1:
        x_min = x[i]
    elif a[i] == 2:
        x_max = x[i]
    elif a[i] == 3:
        y_min = y[i]
    elif a[i] == 4:
        y_max = y[i]

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
xmax=w
ymax=h
xmin=0
ymin=0

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1 and xmin<x:
    xmin=x
  if a==2 and xmax>x:
    xmax=x
  if a==3 and ymin<x:
    ymin=y
  if a==4 and ymax>y:
    ymax=y

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
xmax=w
ymax=h
xmin=0
ymin=0

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    xmin=x
  if a==2:
    xmax=x
  if a==3:
    ymin=y
  if a==4:
    ymax=y

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x0=y0=0
xx=w
yy=h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    if x0<x:
      x0=x
  elif a==2:
    if x<xx:
      xx=x
  elif a==3:
    if y0<y:
      y0=y
  elif a==4:
    if y<yy:
      yy=y
print(max(0,abs((xx-x0)*(yy-y0))))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x0=y0=0
xx=w
yy=h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    if x0<x:
      x0=x
  elif a==2:
    if x<xx:
      xx=x
  elif a==3:
    if y0<y:
      y0=y
  elif a==4:
    if y<yy:
      yy=y
print(max(0,(xx-x0)*(yy-y0)))

Submission status: Wrong Answer

Solution code:
temp = input().rstrip().split(" ")
W = int(temp[0])
H = int(temp[1])
N = int(temp[2])
for i in range(N):
    temp = input().rstrip().split(" ")
    X = int(temp[0])
    Y = int(temp[1])
    A = int(temp[2])
    if A == 1:
        W = W - X
    elif A == 2:
        W = W - (W - X)
    if A == 3:
        H = H - Y
    elif A == 4:
        H = H - (H - Y)
print(W * H)

Submission status: Wrong Answer

Solution code:
temp = input().rstrip().split(" ")
W = int(temp[0])
H = int(temp[1])
N = int(temp[2])

for i in range(N):
    temp = input().rstrip().split(" ")
    X = int(temp[0])
    Y = int(temp[1])
    A = int(temp[2])
    print(W,H,N)

    if A == 1:
        W = W - X
    elif A == 2:
        W = W - (W - X)
    if A == 3:
        H = H - Y
    elif A == 4:
        H = H - (H - Y)
print(W,H,N)
print(W * H)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N):
  x, y, a = map(int,input().split())
  if(a == 1):
    dx = max(dx, x)
  elif(a == 2):
    W = min(W, x)
  elif(a == 3):
    dy = max(dy, y)
  else:
    H = min(H, y)
if(dx <= W or dy <= H):
  print(0)
else:
  print((dx-W) * (dy-H))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(N):
  x, y, a = map(int,input().split())
  if(a == 1):
    dx = max(dx, x)
  elif(a == 2):
    W = min(W, x)
  elif(a == 3):
    dy = max(dy, y)
  else:
    H = min(H, y)
print((dx-W) * (dy-H))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
c = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()])

sx = [0, w]
sy = [0, h]
for i in range(n):
    if c[i][2] == 1:
        if sx[0] < c[i][0]:
            sx[0] = c[i][0]
    elif c[i][2] == 2:
        if sx[1] > c[i][0]:
            sx[1] = c[i][0]
    elif c[i][2] == 3:
        if sy[0] < c[i][1]:
            sy[0] = c[i][1]
    elif c[i][2] == 4:
        if sy[1] > c[i][1]:
            sy[1] = c[i][1]

S = max((sx[1] - sx[0]) * (sy[1] - sy[0]), 0)
print(S)

Submission status: Wrong Answer

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

MINX=0
MAXX=W
MINY=0
MAXY=H

for x,y,a in XYA:
    if a==1:
        MINX=max(MINX,x)
    if a==2:
        MAXX=min(MAXX,x)
    if a==3:
        MINY=max(MINY,y)
    if a==4:
        MAXY=min(MAXY,y)

print(max((MAXY-MINY)*(MAXX-MINX),0))

Submission status: Wrong Answer

Solution code:
import collections as cl

W,H,N = [int(i) for i in input().split()]
action_list = []
ACTION_INDEX = {
	"X" : 0,
	"Y" : 1,
	"TYPE" : 2
}
ACTION_TYPE = {
	"LESS_THAN_X" : 1,
	"MORE_THAN_X" : 2,
	"LESS_THAN_Y" : 3,
	"MORE_THAN_Y" : 4,
}

for i in range(N) :
	action_list.append([int(i) for i in input().split()])

arr = [[0 for i in range(H)] for j in range(W)]

for actions in action_list :
	if(actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["LESS_THAN_X"]) :
		for i in range(actions[ACTION_INDEX["X"]]) :
			for j in range(H) :
				arr[i][j] = 1

	elif (actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["MORE_THAN_X"]) :
		for i in range(actions[ACTION_INDEX["X"]], W) :
			print(i)
			for j in range(H) :
				arr[i][j] = 1
	elif (actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["LESS_THAN_Y"]) :
		for i in range(W) :
			for j in range(actions[ACTION_INDEX["Y"]]) :
				arr[i][j] = 1
	elif (actions[ACTION_INDEX["TYPE"]] == ACTION_TYPE["MORE_THAN_Y"]) :
		for i in range(W) :
			for j in range(actions[ACTION_INDEX["Y"]], H) :
				arr[i][j] = 1

arr2 = []
for i in range(W) :
	for j in range(H) :
		arr2.append(arr[i][j])
c = cl.Counter(arr2)
print(c[0])

Submission status: Wrong Answer

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

for dat in data:
  x,y,a = list(map(int,dat.split()))
  if a == 1 and x > w_0:
    w_0 = x
  elif a == 2 and x < w:
    w = x
  elif a == 3 and y > h_0:
    h_0 = y
  elif a == 4 and y < h:
    h = y
  else:
    continue
    
area = (w-w_0)*(h-h_0)

if area > 0:
  print(area)
else:
  print(0)

Submission status: Wrong Answer

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

for dat in data:
  x,y,a = list(map(int,dat.split()))
  if a == 1 and x > w_0:
    w_0 = x
  elif a == 2 and x < w:
    w = x
  elif a == 3 and y > h_0:
    h_0 = y
  else:
    h = y

area = (w-w_0)*(h-h_0)

if area > 0:
  print(area)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().strip().split(" "))
Sum=0
r=0
xx=0
yy=0
for i in range(N):
    x,y,a=map(int,input().strip().split(" "))
    
    if(a==1):
        if(xx<x):
            xx=x
    elif(a==2):
        if(W>x):
            W=x
    elif(a==3):
        if(yy<y):
            yy=y
    elif(a==4):
        if(H>y):
            H=y
Sum=(W-xx)*(H-yy)

if(Sum<0):
    print("0")
else:
    print(Sum)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().strip().split(" "))
Sum=0
r=0
xx=0
yy=0
for i in range(N):
    x,y,a=map(int,input().strip().split(" "))
    
    if(a==1):
        if(xx<x):
            xx=x
    elif(a==2):
        if(W>x):
            W=x
    elif(a==3):
        if(yy<y):
            yy=y
    elif(a==4):
        if(H>y):
            H=y
print((W-xx)*(H-yy))

Submission status: Wrong Answer

Solution code:
# input
W, H, N = map(int, input().split())
a1 = 0
a2 = W
a3 = 0
a4 = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x >= a1:
            a1 = x
    if a == 2:
        if x <= a2:
            a2 = x
    if a == 3:
        if y >= a3:
            a3 = y
    if a == 4:
        if y <= a4:
            a4 = y

ans = max(0, (a2 - a1) * (a4 - a3))
print(ans)

Submission status: Wrong Answer

Solution code:
# input
W, H, N = map(int, input().split())
a1 = 0
a2 = W
a3 = 0
a4 = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x >= a1:
            a1 = x
    if a == 2:
        if x <= a2:
            a2 = x
    if a == 3:
        if y >= a3:
            a3 = y
    if a == 4:
        if y <= a4:
            a4 = y

ans = (a2 - a1) * (a4 - a3)
print(ans)

Submission status: Wrong Answer

Solution code:
w, h, n = map( int, input().split())
l = 0
r = w
d = 0
u = h
for _ in range(n):
    x, y, a = map( int, input().split())
    if a == 1:
        l = max(l,x)
    elif a == 2:
        r = min(r,x)
    elif a == 3:
        d = max(d,y)
    else:
        u = min(u,y)

print(max(0,(r-l)*(u-d)))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
W, H, N = map(int, input().split())
max_x, max_y = W, H
min_x, min_y = 0, 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if min_x <= x:
            min_x = x
        elif max_x <= x:
            min_x, max_x = 0, 0
    elif a == 2:
        if max_x >= x:
            max_x = x
        elif x <= min_x:
            min_x, max_x = 0, 0
    elif a == 3:
        if min_y <= y:
            min_y = y
        elif max_y <= y:
            min_y, max_y = 0, 0
    else:
        if max_y >= y:
            max_y = y
        elif y <= min_y:
            min_y, max_y = 0, 0
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
W, H, N = map(int, input().split())
max_x, max_y = W, H
min_x, min_y = 0, 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if min_x <= x:
            min_x = x
        elif max_x <= x:
            min_x, max_x = 0, 0
    elif a == 2:
        if max_x >= x:
            max_x = x
        elif x <= min_x:
            min_x, max_x = 0, 0
    elif a == 3:
        if min_y <= y:
            min_y = y
        elif max_y >= y:
            min_y, max_y = 0, 0
    else:
        if max_y >= y:
            max_y = y
        elif y <= min_y:
            min_y, max_y = 0, 0
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
W, H, N = map(int, input().split())
max_x, max_y = W, H
min_x, min_y = 0, 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if min_x <= x:
            min_x = x
        elif max_x <= x:
            max_x = 0
    elif a == 2:
        if max_x >= x:
            max_x = x
    elif a == 3:
        if min_y <= y:
            min_y = y
        elif max_y >= y:
            max_y = 0
    else:
        if max_y >= y:
            max_y = y
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
W, H, N = map(int, input().split())
max_x, max_y = W, H
min_x, min_y = 0, 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        min_x = x
    elif a == 2:
        max_x = x
    elif a == 3:
        min_y = y
    else:
        max_y = y
diff_x = max_x - min_x
diff_y = max_y - min_y
print(0 if diff_x<0 or diff_y<0 else diff_x * diff_y)

Submission status: Wrong Answer

Solution code:
wb,hb,n = list(map(int,input().split()))
d = [input() for i in range(n)]
wa = 0
ha = 0

for i in range(n):
  e = list(map(int,d[i].split()))
  if e[2] == 1 and wa <= e[0]:
    wa = e[0]
  elif e[2] == 2 and wb >= e[0]:
    wb = e[0]
  elif e[2] == 3 and ha <= e[1]:
    ha = e[1]
  elif e[2] == 4 and hb >= e[1]:
    hb = e[1]

if (hb-ha)*(wb-wa) >=0:
  print((hb-ha)*(wb-wa))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, raw_input().split())
L, R, T, B = 0, W, H, 0
pos = []
for i in range(N):
    x, y, a = map(int, raw_input().split())
    if a == 1:
        L = max(x,L)
    elif a == 2:
        R = min(x,R)
    elif a == 3:
        B = max(y,B)
    elif a == 4:
        T = min(y,T)
print max((R-L)*(T-B),0)

Submission status: Wrong Answer

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

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

    if a == 1:
        w = w - x
    elif a == 2:
        w = x
    elif a == 3:
        h = h - y
    elif a == 4:
        h = y

print(w * h)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
xya = []
xl, xr, yu, yt = 0, w, 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
       if xl < x:
           xl = x 
    elif a == 2:
        if xr > x:
            xr = x
    elif a == 3:
        if yu < y:
            yu = y
    else:
        if yt > y:
            yt = y
print(xl, xr, yu, yt)
print([(xr - xl) * (yt - yu), 0][(xr - xl) <= 0 or (xr - xl) <= 0])

Submission status: Wrong Answer

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

a_x = 0
a_y = 0
b_x = W
b_y = 0
c_x = W
c_y = H
d_x = 0
d_y = H

for l in li:
    if l[2] == 1 and l[0] > a_x:
        a_x = l[0]
        d_x = l[0]

    elif l[2] == 2 and l[0] < b_x:
        b_x = l[0]
        c_x = l[0]
    
    elif l[2] == 3 and l[1] > a_y:
        a_y = l[1] 
        b_y = l[1]

    elif l[2] == 4 and l[1] < d_y:
        c_y = l[1]
        d_y = l[1]

print((b_x - a_x)*(d_y - a_y))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
a_list =[] 
for i in range(N):
  a_list.append(list(map(int, input().split())))
a1_list = [i[0] for i in a_list if i[2] == 1 ]
a2_list = [i[0] for i in a_list if i[2] == 2 ]
a3_list = [i[1] for i in a_list if i[2] == 3 ]
a4_list = [i[1] for i in a_list if i[2] == 4 ]
if a1_list == []:
  a1_max = 0
else:
  a1_max = max(a1_list)
if a2_list == []:
  a2_min = W
else:
  a2_min = min(a2_list)
if a3_list ==[]:
  a3_max = 0
else:
  a3_max = max(a3_list)
if a4_list == []:
  a4_min = H
else:
  a4_min = min(a4_list)
S = (a2_min - a1_max)*(a4_min - a3_max)
if S >= 0:
  print(S)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
a_list =[] 
for i in range(N):
  a_list.append(list(map(int, input().split())))
a1_list = [i[0] for i in a_list if i[2] == 1 ]
a2_list = [i[0] for i in a_list if i[2] == 2 ]
a3_list = [i[1] for i in a_list if i[2] == 3 ]
a4_list = [i[1] for i in a_list if i[2] == 4 ]
if a1_list == []:
  a1_max = 0
else:
  a1_max = max(a1_list)
if a2_list == []:
  a2_min = W
else:
  a2_min = min(a2_list)
if a3_list ==[]:
  a3_max = 0
else:
  a3_max = max(a3_list)
if a4_list == []:
  a4_min = H
else:
  a4_min = min(a4_list)
print((a2_min - a1_max)*(a4_min - a3_max))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

xl = 0
xr = W
yu = H
yd = 0

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

    print(x,y,a)
    if a == 1:
        xl = max(xl,x)
    elif a == 2:
        xr = min(xr,x)
    elif a == 3:
        yd = max(yd,y)
    else:
        yu = min(yu,y)

ans = max(0,xr - xl) * max(0,yu - yd)

print(ans)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
tyoten = [0, 0]
ans = W*H
for i in range(N):
    x, y, a = map(int, input().split())
    
    if a == 1:
        
        if tyoten[0] < x < W:
            tyoten[0] = x
        elif W <= x:
            ans = 0
    
    elif a == 2:
        
        if tyoten[0] < x < W:
            W = x
        elif x <= tyoten[0]:
            ans = 0
    
    elif a == 4:
        
        if tyoten[1] < y < H:
            H = y
        elif y < tyoten[1]:
            ans = 0
        
    elif a == 3:
        
        if tyoten[1] < y < H:
            tyoten[1] = y
        elif H < y:
            ans = 0

print(0 if ans == 0 else (W-tyoten[0])*(H-tyoten[1]))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
count = 0
list_prob = []
while count < n:
    list_prob.append(list((map(int, input().split()))))
    count += 1
w_max = w
h_max = h
w_min = 0
h_min = 0

for row in list_prob:
    if row[2] == 1:
        if w_min < row[0]:
            w_min = row[0]
    elif row[2] == 2:
        if w_max > row[0]:
            w_max = row[0]
    elif row[2] == 3:
        if h_min < row[1]:
            h_min = row[1]
    else:
        if h_max > row[1]:
            h_max = row[1]
if w_max < w_min or h_max < h_min:
    print(0)
else:
    print(0,(w_max - w_min)*(h_max - h_min))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
count = 0
list_prob = []
while count < n:
    list_prob.append(list((map(int, input().split()))))
    count += 1
w_max = w
h_max = h
w_min = 0
h_min = 0

for row in list_prob:
    if row[2] == 1:
        if w_min < row[0]:
            w_min = row[0]
    elif row[2] == 2:
        if w_max > row[0]:
            w_max = row[0]
    elif row[2] == 3:
        if h_min < row[1]:
            h_min = row[1]
    else:
        if h_max > row[1]:
            h_max = row[1]
print(max(0,(w_max - w_min)*(h_max - h_min)))

Submission status: Wrong Answer

Solution code:
W,H,N=map(int, input().split())
ls1=[0]
ls2=[W]
ls3=[0]
ls4=[H]
for i in range(N):
    tmp=list(map(int, input().split()))
    if tmp[2]==1:
        ls1.append(tmp[0])
    if tmp[2]==2:
        ls2.append(tmp[0])
    if tmp[2]==3:
        ls3.append(tmp[1])
    if tmp[2]==4:
        ls4.append(tmp[1])
print(max(0,(min(ls2)-max(ls1))*(min(ls4)-max(ls3))))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a1=[0];a2=[5];a3=[0];a4=[4]
for i in a:
  if i[2]==1:a1.append(i[0])
  else:pass
for i in a:
  if i[2]==2:a2.append(i[0])
  else:pass
for i in a:
  if i[2]==3:a3.append(i[1])
  else:pass
for i in a:
  if i[2]==4:a4.append(i[1])
  else:pass
if max(a1)-min(a2)<0:x=max(a1)-min(a2)
else:x=0
if max(a3)-min(a4)<0:y=max(a3)-min(a4)
else:y=0
print(x*y)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a1=[0];a2=[101];a3=[0];a4=[101]
for i in a:
  if i[2]==1:a1.append(i[0])
  else:pass
for i in a:
  if i[2]==2:a2.append(i[0])
  else:pass
for i in a:
  if i[2]==3:a3.append(i[1])
  else:pass
for i in a:
  if i[2]==4:a4.append(i[1])
  else:pass
if max(a1)-min(a2)<0:x=max(a1)-min(a2)
else:x=0
if max(a3)-min(a4)<0:y=max(a3)-min(a4)
else:y=0
print(x*y)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a1=[0];a2=[0];a3=[0];a4=[0]
for i in a:
  if i[2]==1:a1.append(i[0])
  else:pass
for i in a:
  if i[2]==2:a2.append(i[0])
  else:pass
for i in a:
  if i[2]==3:a3.append(i[1])
  else:pass
for i in a:
  if i[2]==4:a4.append(i[1])
  else:pass
if max(a1)-min(a2)<0:x=max(a1)-min(a2)
else:x=0
if max(a3)-min(a4)<0:y=max(a3)-min(a4)
else:y=0
print(x*y)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
a1,a2,a3,a4=0,0,0,0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if a1<x:
            a1=x
    elif a==2:
        if a2<w-x:
            a2=w-x
    elif a==3:
        if a3<y:
            a3=y
    elif a==4:
        if a4<h-y:
            a4=h-y
if ((w-a1-a2)*(h-a3-a4))>=0:
    print((w-a1-a2)*(h-a3-a4))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
a1,a2,a3,a4=0,0,0,0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if a1<x:
            a1=x
    elif a==2:
        if a2<x:
            a2=w-x
    elif a==3:
        if a3<y:
            a3=y
    elif a==4:
        if a4<y:
            a4=h-y
if ((w-a1-a2)*(h-a3-a4))>=0:
    print((w-a1-a2)*(h-a3-a4))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x, y, a = [], [], []
m1 = [0, 0]
m2 = [w, h]
for _ in range(n):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)
for i in range(n):
    if a[i] == 1:
        m1[0] = max(m1[0], x[i])
    elif a[i] == 2:
        m2[0] = min(m2[0], x[i])
    elif a[i] == 3:
        m1[1] = max(m1[1], y[i])
    else:
        m2[1] = min(m2[1], y[i])
s = (m2[0] - m1[0]) * (m2[1] - m1[1])
if s < 0:
  print(0)
else:
  print(s)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x, y, a = [], [], []
m1 = [0, 0]
m2 = [w, h]
for _ in range(n):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)
for i in range(n):
    if a[i] == 1:
        if m1[0] < x[i]:
            m1[0] = x[i]
    elif a[i] == 2:
        if m2[0] > x[i]:
            m2[0] = x[i]
    elif a[i] == 3:
        if m1[1] < y[i]:
            m1[1] = y[i]
    else:
        if m2[1] > y[i]:
            m2[1] = y[i]
s = (m2[0] - m1[0]) * (m2[1] - m1[1])
if s < 0:
    print(0)
else:
    print(s)

Submission status: Wrong Answer

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

memox = [True]*(w+1)
memoy = [True]*(h+1)


for i in range(n):
    xi,yi,a=map(int, input().split())
    if a == 1:
        memox = [False] * xi + memox[xi:]
    elif a == 2:
        memox = memox[:xi+1] + [False] * (w - xi)
    elif a == 3:
        memoy = [False] * yi + memoy[yi:]
    elif a == 4:
        memoy = memoy[:yi+1] + [False] * (h - yi)
memox = [i for i in memox if i]
memoy = [i for i in memoy if i]

print(max([0, (len(memox) - 1) * (len(memoy) - 1)]))

Submission status: Wrong Answer

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

memox = [True]*(w+1)
memoy = [True]*(w+1)


for i in range(n):
    xi,yi,a=map(int, input().split())
    if a == 1:
        memox = [False] * xi + memox[xi:]
    elif a == 2:
        memox = memox[:xi+1] + [False] * (w - xi)
    elif a == 3:
        memoy = [False] * yi + memoy[yi:]
    elif a == 4:
        memoy = memoy[:yi+1] + [False] * (h - yi)
memox = [i for i in memox if i]
memoy = [i for i in memoy if i]

print(max([0, (len(memox) - 1) * (len(memoy) - 1)]))

Submission status: Wrong Answer

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)

xmin = 0
xmax = w
ymin = 0
ymax = h

for i in range(n):
    if a[i] == 1:
        xmin = max(xmin, x[i])
    elif a[i] == 2:
        xmax = min(xmax, x[i])
    elif a[i] == 3:
        ymin = max(ymin, y[i])
    elif a[i] == 4:
        ymax = min(ymax, y[i])

print((xmax - xmin) * (ymax - ymin))

Submission status: Wrong Answer

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

top = H
btm = 0
left = 0
right = W
for x,y,a in src:
    if a == 1:
        left = max(left,x)
    elif a == 2:
        right = min(right,x)
    elif a == 3:
        btm = max(btm,y)
    else:
        top = min(top,y)
area = (right-left) * (top-btm)
print(max(0, area))

Submission status: Wrong Answer

Solution code:
import sys

w,h,n = (int(_) for _ in input().split())
xa = ya = 0
xb = w
yb = h

for i in range(n):
    x,y,a=(int(_) for _ in input().split())
    if(a == 1):
        if(xa <= x):
            xa = x
    elif (a == 2):
        if (xb >= x):
            xb = x
    elif (a == 3):
        if (ya <= y):
            ya = y
    elif (a == 4):
        if (yb >= y):
            yb = y
    else:
        sys,exit(1)


ans = (xb-xa)*(yb-ya)
print(ans) if ans >= 0 else print('0')

Submission status: Wrong Answer

Solution code:
import sys

w,h,n = (int(_) for _ in input().split())
xa = ya = 0
xb = w
yb = h

for i in range(1,n+1):
    x,y,a=(int(_) for _ in input().split())
    if(a == 1):
        if(xa <= x):
            xa = x
    elif (a == 2):
        if (xb >= x):
            xb = x
    elif (a == 3):
        if (ya <= y):
            ya = y
    elif (a == 4):
        if (yb >= y):
            yb = y
    else:
        sys,exit(1)


ans = (xb-xa)*(yb-ya)
print(ans) if ans >= 0 else print('0')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
x_low,y_low,x_high,y_high = 0,0,w,h
for i in range(n):
    x,y,ver = map(int,input().split())

    if ver == 1:
        x_low = max(x_low,x)
    elif ver == 2:
        x_high = min(x_high,x)
    elif ver == 3:
        y_low = max(y_low,y)
    elif ver == 4:
        y_high = min(y_high,y)
total = (x_high-x_low)*(y_high-y_low)
print(total if total > 0 else 0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 12 13:14:59 2018
ABC047B
@author: maezawa
"""
w, h, n = list(map(int, input().split()))
xl = 0
xu = w
yl = 0
yu = h

for i in range(n):
    xi, yi, ai = list(map(int, input().split()))
    if ai == 1:
        if xl < xi:
            xl = xi
    elif ai == 2:
        if xu > xi:
            xu = xi
    elif ai == 3:
        if yl < yi:
            yl = yi
    else:
        if yu > yi:
            yu = yi

ans = (xu-xl)*(yu-yl)
if ans < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 12 13:14:59 2018
ABC047B
@author: maezawa
"""
w, h, n = list(map(int, input().split()))
xl = 0
xu = w
yl = 0
yu = h

for i in range(n):
    xi, yi, ai = list(map(int, input().split()))
    if ai == 1:
        xl = xi
    elif ai == 2:
        xu = xi
    elif ai == 3:
        yl = yi
    else:
        yu = yi

ans = (xu-xl)*(yu-yl)
if ans < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
#47b
w,h,n = map(int,input().split())
x,y=0,0

for _ in range(n):
    xi,yi,a = map(int,input().split())
    if a==1:
        x = max(x,xi)
    elif a==2:
        w = min(xi,w)
    elif a==3:
        y = max(y,yi)
    else:
        h = min(h,yi)
ans = (w-x)*(h-y)   

print(ans if ans>=0 else (0))