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

CoordinateList1 = []
CoordinateList2 = []
CoordinateList3 = []
CoordinateList4 = []
for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        CoordinateList1.append(x)
    elif a == 2:
        CoordinateList2.append(x)
    elif a == 3:
        CoordinateList3.append(y)
    elif a == 4:
        CoordinateList4.append(y)
# X
a1 = 0
if sorted(CoordinateList1) != []:
    a1 = sorted(CoordinateList1)[-1]
a2 = W
if sorted(CoordinateList2) != []:
    a2 = sorted(CoordinateList2)[0]

# Y
a3 = 0
if sorted(CoordinateList3) != []:
    a3 = sorted(CoordinateList3)[-1]
a4 = H
if sorted(CoordinateList4) != []:
    a4 = sorted(CoordinateList4)[0]


print((int(a2)-int(a1))*(int(a4)-int(a3)))

Submission status: Wrong Answer

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

CoordinateList1 = []
CoordinateList2 = []
CoordinateList3 = []
CoordinateList4 = []
for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        CoordinateList1.append([x,a])
    elif a == 2:
        CoordinateList2.append([x,a])
    elif a == 3:
        CoordinateList3.append([y,a])
    elif a == 4:
        CoordinateList4.append([y,a])

# X
a1 = 0
if sorted(CoordinateList1) != []:
    a1 = sorted(CoordinateList1)[-1][0]
a2 = W
if sorted(CoordinateList2) != []:
    a2 = sorted(CoordinateList2)[0][0]

# Y
a3 = 0
if sorted(CoordinateList3) != []:
    a3 = sorted(CoordinateList3)[-1][0]
a4 = H
if sorted(CoordinateList4) != []:
    a4 = sorted(CoordinateList4)[0][0]

print((int(a2)-int(a1))*(int(a4)-int(a3)))

Submission status: Wrong Answer

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

CoordinateList1 = []
CoordinateList2 = []
CoordinateList3 = []
CoordinateList4 = []
for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        CoordinateList1.append([x,y,a])
    elif a == 2:
        CoordinateList2.append([x,y,a])
    elif a == 3:
        CoordinateList3.append([x,y,a])
    elif a == 4:
        CoordinateList4.append([x,y,a])

# X
a1 = 0
if sorted(CoordinateList1) != []:
    a1 = sorted(CoordinateList1)[-1][0]
a2 = W
if sorted(CoordinateList2) != []:
    a2 = sorted(CoordinateList2)[0][0]

# Y
a3 = 0
if sorted(CoordinateList3) != []:
    a3 = sorted(CoordinateList3)[-1][1]
a4 = H
if sorted(CoordinateList4) != []:
    a4 = sorted(CoordinateList4)[0][1]

print((int(a2)-int(a1))*(int(a4)-int(a3)))

Submission status: Wrong Answer

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

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

# raw White & Black
AllArea = []
for numline in range(H):
    rawWhite = []
    rawBlack = []
    for numraw in range(W):
        rawWhite.append("W")
        rawBlack.append("B")
    AllArea.append(rawWhite)
print(AllArea)
# coloring from white to Black
for n in range(N):
    if CoordinateList[n][2] == 1:
        if CoordinateList[n][0] == 0:
             pass
        else:
            for i in range(H):
                del AllArea[i][:(CoordinateList[n][0])]
                for numX in range(CoordinateList[n][0]):
                    AllArea[i].insert(0,"B")

    elif CoordinateList[n][2] == 2:
        if CoordinateList[n][0] == 0:
            print(0)
            exit()
        else:
            for i in range(H):
                del AllArea[i][(CoordinateList[n][0]):]
                for numX in range(CoordinateList[n][0]):
                    AllArea[i].append("B")

    elif CoordinateList[n][2] == 3:
        changeY = H - int(CoordinateList[n][1])
        if changeY == 0:
            print(0)
            exit()
        else:
            del AllArea[changeY:]
            
            for changeRaw in range(int(CoordinateList[n][1])):
                AllArea.append(rawBlack)
            print(AllArea)
         

    elif CoordinateList[n][2] == 4:
        changeY = H - int(CoordinateList[n][1]) 
        if changeY == 0:
            pass
        else:
            del AllArea[:changeY]
            print(AllArea)
            for changeRaw in range(changeY):
                AllArea.insert(0,rawBlack)
            
print(AllArea)            
# counting 
AreaWhite = 0
for i in range(H):
    AreaWhite += AllArea[i].count("W")

print(AreaWhite)

Submission status: Wrong Answer

Solution code:
W,H,N = map(int, input().strip().split(' '))
x1,x2 = 0,W
y1,y2 = 0,H
for _ in range(N):
  x,y,a = map(int, input().strip().split(' '))
  if a == 1:
    x1 = max(x1, x)
  elif a == 2:
    x2 = min(x2, x)
  elif a == 3:
    y1 = max(y1, y)
  else:
    y2 = min(y2, y)

s = (x2-x1)*(y2-y1)
print(max(0, s))

Submission status: Wrong Answer

Solution code:
W,H,N = map(int, input().split())
l, r, d, u = 0,W,0,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(l,r,d,u)
print(max(0,(r-l)*(u-d)))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().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 and x > x_min:
        x_min = x
    elif a == 2 and x < x_max:
        x_max = x
    elif a == 3 and y > y_min:
        y_min = y
    elif a == 4 and y < y_max:
        y_max = y
x_l = x_max - x_min
y_l = y_max - y_min
if x_l > 0 or y_l > 0:
    S = (x_max - x_min) * (y_max - y_min)
else:
    S = 0
print(S)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().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 = x
    elif a == 2:
        x_max = x
    elif a == 3:
        y_min = y
    else:
        y_max = y
if (x_max - x_min) <= 0 or (y_max - y_min) < 0:
    S = 0
else:
    S = (x_max - x_min) * (y_max - y_min)
print(S)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    w, h, n = map(int, input().split())
    px = py = 0
    points = [[px, py], [w, h]]
    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            points[0][0] = max(px, x)
        elif a == 2:
            points[1][0] = min(w, x)
        elif a == 3:
            points[0][1] = max(py, y)
        elif a == 4:
            points[1][1] = min(h, y)

    print(max(0, points[1][0]-points[0][0]) * max(0, points[1][1]-points[0][1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    w, h, n = map(int, input().split())
    px = py = 0
    points = [[px, py], [w, h]]
    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            points[0][0] = max(px, x)
        elif a == 2:
            points[1][0] = min(w, x)
        elif a == 3:
            points[0][1] = max(py, y)
        elif a == 4:
            points[1][1] = min(h, y)

    area = (points[1][0]-points[0][0]) * (points[1][1]-points[0][1])
    print(area if area >= 0 else 0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
    w, h , n = map(int, input().split())
    points = [[0,0], [w, h]]
    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            points[0][0] = x
        elif a == 2:
            points[1][0] = x
        elif a == 3:
            points[0][1] = y
        elif a == 4:
            points[1][1] = y
        
    area = (points[1][0]-points[0][0]) * (points[1][1]-points[0][1])
    print(area if area >=    0 else 0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ws = 0
we = w
hs = 0
he = h

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        ws = max(ws, x)
    elif a == 2:
        we = min(we, x)
    elif a == 3:
        hs = max(hs, y)
    else:
        he = min(he, y)

print(max(0, (we - ws) * (he - hs)))

Submission status: Wrong Answer

Solution code:
[w,h,n]=list(map(int,input().split()))
risuto=[]
xmin=0
xmax=w
ymin=0
ymax=h
for i in range(n):
	risuto.append(list(map(int,input().split())))
for i in range(n):
	if risuto[i][2]==1 and risuto[i][0]>xmin:
		xmin=risuto[i][0]
	elif risuto[i][2]==2 and risuto[i][0]<xmax:
		xmax=risuto[i][0]
	elif risuto[i][2]==3 and risuto[i][1]>ymin:
		ymin=risuto[i][1]
	elif risuto[i][2]==4 and risuto[i][1]<ymax:
		ymax=risuto[i][1]
menseki=int((xmax-xmin)*(ymax-ymin))
if menseki<0:
	menseki=0
print(menseki)

Submission status: Wrong Answer

Solution code:
[w,h,n]=list(map(int,input().split()))
risuto=[]
xmin=0
xmax=w
ymin=0
ymax=h
for i in range(n):
	risuto.append(list(map(int,input().split())))
for i in range(n):
	if risuto[i][2]==1 and risuto[i][0]>xmin:
		xmin=risuto[i][0]
	elif risuto[i][2]==2 and risuto[i][0]<xmax:
		xmax=risuto[i][0]
	elif risuto[i][2]==3 and risuto[i][1]>ymin:
		ymin=risuto[i][1]
	elif risuto[i][2]==4 and risuto[i][1]<ymax:
		ymax=risuto[i][1]
menseki=int((xmax-xmin)*(ymax-ymin))
print(menseki)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    w, h, n = map(int, input().split())
    triples = []
    for i in range(n):
        triples.append(tuple(map(int, input().split())))

    one = []
    two = []
    three = []
    four = []
    for triple in triples:
        if triple[2] == 1:
            one.append(triple)
        elif triple[2] == 2:
            two.append(triple)
        elif triple[2] == 3:
            three.append(triple)
        else:
            four.append(triple)
    maxOne, minTwo, maxThree, minFour = 0, w, 0, h
    if len(one):
        maxOne = sorted(one, key=lambda tup: tup[0], reverse=True)[0][0]
    if len(two):
        minTwo = sorted(two, key=lambda tup: tup[0])[0][0]
    if len(three):
        maxThree = sorted(three, key=lambda tup: tup[1], reverse=True)[0][1]
    if len(four):
        minFour = sorted(four, key=lambda tup: tup[1])[0][1]

    print(max(0, (w - maxOne - (w - minTwo)) * (h - maxThree - (h - minFour))))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    w, h, n = map(int, input().split())
    triples = []
    for i in range(n):
        triples.append(tuple(map(int, input().split())))

    one = []
    two = []
    three = []
    four = []
    for triple in triples:
        if triple[2] == 1:
            one.append(triple)
        elif triple[2] == 2:
            two.append(triple)
        elif triple[2] == 3:
            three.append(triple)
        else:
            four.append(triple)
    maxOne, minTwo, maxThree, minFour = 0, w, 0, h
    if len(one):
        maxOne = sorted(one, key=lambda tup: tup[0], reverse=True)[0][0]
    if len(two):
        minTwo = sorted(two, key=lambda tup: tup[0])[0][0]
    if len(three):
        maxThree = sorted(three, key=lambda tup: tup[1], reverse=True)[0][1]
    if len(four):
        minFour = sorted(four, key=lambda tup: tup[1])[0][1]

    print("{a} {b} {c} {d}".format(a=maxOne, b=minTwo, c=maxThree, d=minFour))
    print(max(0, (w - maxOne - (w - minTwo)) * (h - maxThree - (h - minFour))))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
S = [input().split() for i in range(N)]
a1 = []
a2 = []
a3 = []
a4 = []
for i in range(N):
   for j in range(3):
      S[i][j] = int(S[i][j])
for i in range(N):
  if S[i][2] == 1:
    a1.append(S[i][0])
  elif S[i][2] == 2:
    a2.append(S[i][0])
  elif S[i][2] == 3:
    a3.append(S[i][1])
  else:
    a4.append(S[i][1])
if a1 == []:
  A1 = 0
else:
  A1 = max(a1)
if a2 == []:
  A2 = 0
else:
  A2 = min(a2)
if a3 == []:
  A3 = 0
else:
  A3 = max(a3)
if a4 == []:
  A4 = 0
else:
  A4 = min(a4)
white = W*H - (A1+W-A2)*H -(A3+H-A4)*W
if white<=0:
  print(0)
else:
  print(white)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
X=[w for w in range(W+1)]
Y=[h for h in range(H+1)]
#print(X,Y)
for n in range(N):
    w,h,a=map(int,input().split())
    if a==1:
        X=[x for x in X if x>=w]
    elif a==2:
        X=[x for x in X if x<=w]
    elif a==3:
        Y=[y for y in Y if y>=h]
    else:
        Y=[y for y in Y if y<=h]
    #print(X,Y)
print(max(0,(len(X)-1)*(len(Y)-1)))

Submission status: Wrong Answer

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

x1,x2 = 0,W
y1,y2 = 0,H

for i in range(N):
    x,y,a = Data[i]
    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(x1,x2,y1,y2)

if x2 >= x1 and y2 >= y1:
    s = (x2-x1)*(y2-y1)
else:
    s = 0
print(s)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(N)]
xmax = 0 # a=1
xmin = W # a=2
ymax = 0 # a=3
ymin = H # a=4

for x,y,a in data:
    if a == 1: # x以下
        xmax = max(x, xmax)
    elif a == 2: # x以上
        xmin = min(x, xmin)
    elif a == 3: # y以下
        ymax = max(y, ymax)
    else: # y以上
        ymin = min(y, ymin)
S = (xmin - xmax) * (ymin - ymax)
print(S if S>=0 else 0)

Submission status: Wrong Answer

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

xmax = 0 # a=1
xmin = W # a=2
ymax = 0 # a=3
ymin = H # a=4

for x,y,a in data:
    if a == 1: # x以下
        xmax = max(x, xmax)
    elif a == 2: # x以上
        xmin = min(x, xmin)
    elif a == 3: # y以下
        ymax = max(y, ymax)
    else: # y以上
        ymin = min(y, ymin)
S = (xmin - xmax) * (ymin - ymax)
print(S if S>=0 else 0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
XYA = [list(map(int, input().split())) for _ in range(N)]
x1, x2, y1, y2 = 0, W, 0, H
for x, y, a in XYA:
    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)
if x2 > x1 and y2 > y1:
    print((x2-x1)*(y1-y2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
XYA = [list(map(int, input().split())) for _ in range(N)]
x1, x2, y1, y2 = 0, W, 0, H
for x, y, a in XYA:
    if a == 1:
        x1 = max(x1, x)
    elif a == 2: 
        x2 = max(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    elif a == 4:
        y2 = max(y2, y)
if x2 > x1 and y2 > y1:
    print((x2-x1)*(y1-y2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
XYA = [list(map(int, input().split())) for _ in range(N)]
x1, x2, y1, y2 = 0, W, 0, H
for xya in XYA:
    x, y, a = xya[0], xya[1], xya[2]
    if a == 1 and x >= x1:
        x1 = x
    elif a == 2 and x <= x2: 
        x2 = x
    elif a == 3 and y >= y1:
        y1 = y
    elif a == 4 and y <= y2:
        y2 = y
res = (x2-x1)*(y2-y1)
if res > 0:
    print(res)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
XYA = [list(map(int, input().split())) for _ in range(N)]
x1, x2, y1, y2 = 0, W, 0, H
for xya in XYA:
    x, y, a = xya[0], xya[1], xya[2]
    if a == 1:
        if x >= x1:
            x1 = x
    elif a == 2:
        if x <= x2:
            x2 = x
    elif a == 3:
        if y >= y1:
            y1 = y
    else:
       if y <= y2:
           y2 = y
res = (x2-x1)*(y2-y1)
if res > 0:
    print(res)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
XYA = [list(map(int, input().split())) for _ in range(N)]
x1, x2, y1, y2 = 0, W, 0, H
for xya in XYA:
    if xya[-1] == 1:
        if xya[0] > x1:
            x1 = xya[0]
    elif xya[-1] == 2:
        if xya[0] < x2:
            x2 = xya[0]
    elif xya[-1] == 3:
        if xya[1] > y1:
            y1 = xya[1]
    else:
       if xya[1] < y2:
           y2 = xya[1]
res = (x2-x1)*(y2-y1)
if res >= 0:
    print(res)
else:
    print(0)

Submission status: Wrong Answer

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

s = [[int(i) for i in input().split()] for j in range(n)]

u_left = 0
v_low = 0
u_right = w
v_high = h

for num in s:
    x = num[0]
    y = num[1]
    a = num[2]
    if a == 1 and x >= u_left:
        u_left = x
    elif a == 2 and x <= u_right:
        u_right = x
    elif a == 3 and y >= v_low:
        v_low = y
    elif a == 4 and y <= v_high:
        v_high = y

s = (u_right-u_left)*(v_high-v_low)
print(s if s >= 0 else 0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
X = [0, 0, W, 0, H]
for k in range(N):
  x,y,a = map(int, input().split())
  if a == 1:
    X[a] = max(x,X[a])
  elif a == 2:
    X[a] = min(x,X[a])
  elif a == 3:
    X[a] = max(y,X[a])
  else:
    X[a] = min(y,X[a])
tate = X[4] - X[3]
yoko = X[2] - X[1]
ans = tate*yoko
if ans >= 0:
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xya = [tuple(map(int, input().split())) for _ in range(N)]
print(0)

Submission status: Wrong Answer

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

l = 0
r = W
d = 0
u = H

for x, y, a in xya:
    if a==1:
        l = x
    elif a ==2:
        r = x
    elif a==3:
        d = y
    else:
        u = y

if r>l and u>d:
    print((r-l)*(u-d))
else:
    print(0)

Submission status: Wrong Answer

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

l = 0
r = W
d = 0
u = H

for x, y, a in xya:
    if a==1:
        l = x
    elif a ==2:
        r = x
    elif a==3:
        d = y
    else:
        u = y
        
print(max(0,(r-l)*(u-d)))

Submission status: Wrong Answer

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

l = 0
r = W
d = 0
u = H

for x, y, a in xya:
    if a==1:
        l = x
    elif a ==2:
        r = x
    elif a==3:
        d = y
    else:
        u = y
        
print((r-l)*(u-d))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xmax = W
xmin = 0
ymax = H
ymin = 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        xmin = max(xmin, x)
    elif a == 2:
        xmax = min(xmax, x)
    elif a == 3:
        ymin = max(ymin, y)
    else:
        ymax = min(ymax, y)

print(max(0, (ymax - ymin) * (xmax - xmin)))

Submission status: Wrong Answer

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

print( max((w-min_x)*(h-min_y), 0) )

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
min_x, min_y = 0, 0
w, h = abs(w), abs(h)
for _ in range(n):
    x, y, a = map(int, input().split())
    x, y = abs(x), abs(y)
    if a == 1:
        min_x = x
    elif a == 2:
        w = x
    elif a == 3:
        min_y = y
    else:
        h = y

print( max((w-min_x)*(h-min_y), 0) )

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
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:
        w = x
    elif a == 3:
        min_y = y
    else:
        h = y

print( max((w-min_x)*(h-min_y), 0) )

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
w_max=W
w_min=0
h_max=H
h_min=0
for _ in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        w_min=max(w_min,x)
    elif a==2:
        w_max=min(w_max,x)
    elif a==3:
        h_min=max(h_min,y)
    else:
        h_max=min(h_max,y)
print(max((w_max-w_min)*(h_max-h_min),0))

Submission status: Wrong Answer

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

for i in range(n):
    xi, yi, ai = map(int, input().split())
    if ai == 1 and xi > x:
        x = xi
    if ai == 2 and xi < w:
        x = xi
    if ai == 3 and yi > y:
        y = yi
    if ai == 4 and yi < h:
        y = yi

if w <= x or h <= y:
    res = 0
else:
    res = (w-x) * (h-y)
print(res)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
sx, gx, sy, gy = 0, w, 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and sx < x:
        sx = x
    if a == 2 and gx > x:
        gx = x
    if a == 3 and sy < y:
        sy = y
    if a == 4 and gy > y:
        gy = y
print(max((gx-sx)*(gy-sy), 0))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
sx, gx, sy, gy = 0, w, 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = x
    if a == 2:
        gx = x
    if a == 3:
        sy = y
    if a == 4:
        gy = y
print(max((gx-sx)*(gy-sy), 0))

Submission status: Wrong Answer

Solution code:
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:
        a1.append(x)
    elif a==2:
        a2.append(x)
    elif a==3:
        a3.append(y)
    else:
        a4.append(y)
w=(0 if w-max(a1)-w+min(a2)<0 else w-max(a1)-w+min(a2))
h=(0 if h-max(a3)-h+min(a4)<0 else w-max(a1)-w+min(a2))
print(w*h)

Submission status: Wrong Answer

Solution code:
import numpy as np
W, H, N = map(int, input().split())

g = np.array([[1] * W for _ in range(H)])

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

print (g.sum())

Submission status: Wrong Answer

Solution code:
W, H, N =map(int,input().split())
xya = [list(map(int,input().split())) for i in range(N)]
lxy=[0,0]
rxy=[W,H]
for i in range(N):
    if xya[i][2]==1:
        lxy[0] = max(lxy[0],xya[i][0])
    elif xya[i][2]==2:
        rxy[0] = min(rxy[0],xya[i][0])
    elif xya[i][2]==3:
        lxy[1] = max(lxy[1],xya[i][1])
    else: rxy[1] = min(rxy[1],xya[i][1])
print(max(0, (rxy[1]-lxy[1])*(rxy[0]-lxy[0])))

Submission status: Wrong Answer

Solution code:
W, H, N =map(int,input().split())
xya = [list(map(int,input().split())) for i in range(N)]
lxy=[0,0]
rxy=[W,H]
for i in range(N):
    if xya[i][2]==1:
        lxy[0] = max(lxy[0],xya[i][0])
    if xya[i][2]==2:
        rxy[0] = min(rxy[0],xya[i][0])
    if xya[i][2]==3:
        lxy[1] = max(lxy[1],xya[i][1])
    if xya[i][2]==4:
        rxy[1] = min(rxy[1],xya[i][1])
print(max(0, (rxy[1]-lxy[1])*(rxy[0]-lxy[0])))

Submission status: Wrong Answer

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

X = 0
Y = 0

for i in range(N):
    if lst[i][2] == 1:
        X = lst[i][0]
    elif lst[i][2] == 2:
        W = lst[i][0]
    elif lst[i][2] == 3:
        Y = lst[i][1]
    elif lst[i][2] == 4:
        H = lst[i][1]

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

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
xl, xr, yl, yh= 0, w, 0, h

for _ in range(n):
  a, b, c = map(int, input().split())
  if c == 1:
    xl = max(xl, a)
  elif c == 2:
    xr = min(xr, a)
  elif c == 3:
    yl = max(yl, b)
  else:
    yh = min(yh, b)
if yh - yl >= 0 or xr - xl >= 0:
  print((yh - yl) * (xr - xl))
else :
  print(0)

Submission status: Wrong Answer

Solution code:
#ABC47B
w,h,n = map(int,input().split())
m =[list(map(int, input().split())) for x in range(n)]

#location
z1 =[0,0]
z2 =[w,h]

for i in range(n):
  if m[i][2]==1 and z1[0] <= m[i][0]:
    z1[0] =m[i][0]
  elif m[i][2] ==2 and z2[0] >= m[i][0]:
    z2[0] =m[i][0]
  elif m[i][2] ==3 and z1[1] <=m[i][1]:
    z1[1] =m[i][1]
  elif m[i][2] ==4 and z2[1] >=m[i][2]:
    z2[1] =m[i][1]
if z2[0] > z1[0] and z2[1] > z1[1]:
  print((z2[0]-z1[0])*(z2[1]-z1[1]) )
else:
  print(0)

Submission status: Wrong Answer

Solution code:
# wrong answer

w_right, h_top, n = map(int, input().split())
w_left, h_bottom = 0, 0

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if w_left < x:
            w_left = x
    elif a == 2:
        if w_right > x:
            w_right = x
    elif a == 3:
        if h_bottom < y:
            h_bottom = y
    elif a == 4:
        if h_top > y:
            h_top = y

print(max((w_right - w_left) * (h_top - h_bottom), 0))

Submission status: Wrong Answer

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

minx=w
maxx=0
miny=h
maxy=0
for x,y,a in xya:
    if a==2:
        maxx=max(maxx,x)
    elif a==1:
        minx=min(minx,x)
    elif a==4:
        maxy=max(maxy,y)
    elif a==3:
        miny=min(miny,y)

x=max(0,maxx-minx)
y=max(0,maxy-miny)
print(x*y)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(n)]
_w = [0, w]
_h = [0, h]
for x, y, a in points:
    if a == 1:
        _w[0] = x
    elif a == 2:
        _w[1] = x
    elif a == 3:
        _h[0] = y
    elif a == 4:
        _h[1] = y
width = _w[1] - _w[0] if _w[1] - _w[0] > 0 else 0
height = _h[1] - _h[0] if _h[1] - _h[0] > 0 else 0
print(width * height)

Submission status: Wrong Answer

Solution code:
from enum import IntEnum


class Sides(IntEnum):
    Left = 1
    Right = 2
    Bottom = 3
    Top = 4


width, height, n = (int(x) for x in input().split())

left, right, bottom, top = 0, width, 0, height

for i in range(n):
    x, y, a = (int(x) for x in input().split())
    if a == Sides.Left:
        left = max(left, x)
    elif a == Sides.Right:
        right = min(right, x)
    elif a == Sides.Bottom:
        bottom = max(bottom, y)
    elif a == Sides.Top:
        top = min(top, y)

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

Submission status: Wrong Answer

Solution code:
def resolve():
    w, h, n = map(int, input().split())
    min_x, min_y = 0, 0
    max_x, max_y = w, h
    for _ in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            min_x = min(min_x, x)
        elif a == 2:
            max_x = max(max_x, x)
        elif a == 3:
            min_y = min(min_y, y)
        elif a == 4:
            max_y = max(max_y, y)
    if min_x >= max_x or min_y >= max_y:
        print(0)
    else:
        print((max_x - min_x) * (max_y - min_y))


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    W, H, N = map(int, input().split())
    x = [0 for i in range(N)]
    y = [0 for i in range(N)]
    a = [0 for i in range(N)]
    for i in range(N):
        x[i], y[i], a[i] = map(int, input().split())
        
    left = 0
    right = W
    top = H
    bottom = 0
    
    for i in range(N):
        if a[i] == 1:
            left = x[i]
        elif a[i] == 2:
            right = x[i]
        elif a[i] == 3:
            bottom = y[i]
        elif a[i] == 4:
            top = y[i]
    
    if left < right and bottom < top:
        print((top - bottom) * (right - left))
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
a = [0,0] #左下の座標
b = [w,h] #右上の座標

for i in range(n):
    x,y,z = map(int,input().split())
    if z==1 and a[0]<x:
        a[0] = x
    elif z==2 and b[0]>x:
        b[0] = x
    elif z==3 and a[1]<y:
        a[1] = y
    elif z==4 and b[1]>y:
        b[1] = y
    print(a,b)
if a[0]<b[0] and a[1]<b[1]:
    print((b[0]-a[0])*(b[1]-a[1]))
else:
    print(0)