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:
maxX, maxY, a = map(int, input().split())
minX = minY = 0
for i in range(a):
    x, y, b = map(int, input().split())
    if b == 1:
        minX = x
    elif b == 2:
        maxX = x
    elif b == 3:
        minY = y
    elif b == 4:
        maxY = y
print(max(((maxX - minX)*(maxY - minY),0)))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x_1=[0]
x_2=[w]
y_1=[0]
y_2=[h]

for i in range(n):
    tmp_x,tmp_y,tmp_a=map(int,input().split())
    if tmp_a==1:
        x_1.append(tmp_x)
    elif tmp_a==2:
        x_2.append(tmp_x)
    elif tmp_a==3:
        y_1.append(tmp_y)
    elif tmp_a==4:    
        y_2.append(tmp_y)
        
ans=max(0,(min(x_2)-max(x_1))*(min(y_2)-max(y_1)))

print(ans)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x_1=[0]
x_2=[w]
y_1=[0]
y_2=[h]

for i in range(n):
    tmp_x,tmp_y,tmp_a=map(int,input().split())
    if tmp_a==1:
        x_1.append(tmp_x)
    elif tmp_a==2:
        x_2.append(tmp_x)
    elif tmp_a==3:
        y_1.append(tmp_y)
    else:    
        y_2.append(tmp_y)
        
ans=max(0,(min(x_2)-max(x_1))*(min(y_2)-max(y_1)))

print(ans)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x_1=[0]
x_2=[w]
y_1=[0]
y_2=[h]
a=[]
for i in range(n):
    tmp_x,tmp_y,tmp_a=map(int,input().split())
    if tmp_a==1:
        x_1.append(tmp_x)
    elif tmp_a==2:
        x_2.append(tmp_x)
    elif tmp_a==3:
        y_1.append(tmp_y)
    else:    
        y_2.append(tmp_y)
        
x_min=max(0,max(x_1))
x_max=min(w,min(x_2))
y_min=max(0,max(y_1))
y_max=min(h,min(y_2))

ans=max(0,(x_max-x_min)*(y_max-y_min))

print(ans)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
arr = [[int(i) for i in input().split()] for j in range(n)]
x1, y1, x2, y2 = 0, 0, w, h

for i in arr:
    x, y, a = 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(max((x2-x1)*(y2-y1), 0))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
arr = [[int(i) for i in input().split()] for j in range(n)]
x1, y1, x2, y2 = 0, 0, w, h

for i in arr:
    x, y, a = i
    if a == 1:
        x1 = x
    elif a == 2:
        x2 = x
    elif a == 3:
        y1 = y
    elif a == 4:
        y2 = y

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

Submission status: Wrong Answer

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

minx = 0
miny = 0
MAXx = W
MAXy = H

for k in range(N):
    if list[k][2] == 1:
        minx = max(list[k][0], minx)
    elif list[k][2] == 2:
        MAXx = min(list[k][0], MAXx)
    elif list[k][2] == 3:
        miny = max(list[k][1], miny)
    elif list[k][2] == 4:
        MAXy = min(list[k][1], MAXy)

print(max((MAXx - minx)*(MAXy - miny), 0))

Submission status: Wrong Answer

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

x_min = 0
y_min = 0
x_max = w
y_max = h
for a in coord_list:
    if a[2] == 1:
        x_min = max(a[0], x_min)
    elif a[2] == 2:
        x_max = min(a[0], x_max)
    elif a[2] == 3:
        y_min = max(a[1], y_min)
    elif a[2] == 4:
        y_max = min(a[1], y_max)

ans = max((x_max - x_min) * (y_max - y_min), 0)
print(ans)

Submission status: Wrong Answer

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

x_min = 0
y_min = 0
x_max = w
y_max = h
for a in coord_list:
    if a[2] == 1:
        x_min = max(a[0], x_min)
    elif a[2] == 2:
        x_max = min(a[0], x_max)
    elif a[2] == 3:
        y_min = max(a[1], y_min)
    elif a[2] == 4:
        y_list = min(a[1], y_max)

ans = max((x_max - x_min) * (y_max - y_min), 0)
print(ans)

Submission status: Wrong Answer

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

x_min = 0
y_min = 0
x_max = w
y_max = h
for a in coord_list:
    if a[2] == 1:
        x_min = max(a[0], x_min)
    elif a[2] == 2:
        x_max = min(a[0], x_max)
    elif a[2] == 3:
        y_min = max(a[1], y_min)
    elif a[2] == 4:
        y_list = min(a[1], y_max)

print((x_max - x_min) * (y_max - y_min))

Submission status: Wrong Answer

Solution code:
from sys import stdin
W,H,N = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])

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

for i in data:
    if i[2] == 1:
        x1 = max(x1,i[0])
    if i[2] == 2:
        x2 = min(x2,i[0])
    if i[2] == 3:
        y1 = max(y1,i[1])
    if i[2] == 4:
        y2 = min(y2,i[1])
#print(x1,x2,y1,y2)
print(max((x2-x1)*(y2-y1),0))

Submission status: Wrong Answer

Solution code:
from sys import stdin
W,H,N = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])

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

for i in data:
    if i[2] == 1:
        x1 = max(x1,i[0])
    if i[2] == 2:
        x2 = min(x2,i[0])
    if i[2] == 3:
        y1 = max(y1,i[1])
    if i[2] == 4:
        y2 = min(y2,i[1])
print(x1,x2,y1,y2)
print(max((x2-x1)*(y2-y1),0))

Submission status: Wrong Answer

Solution code:
from sys import stdin
W,H,N = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])

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

for i in data:
    if i[2] == 1:
        x1 = max(x1,i[0])
    if i[2] == 2:
        x2 = min(x2,i[0])
    if i[2] == 3:
        y1 = max(y1,i[1])
    if i[2] == 4:
        y2 = min(y2,i[1])
print((x2-x1)*(y2-y1))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
xmin = 0
ymin = 0
xmax = w
ymax = h
for i in range(n):
    if l[i][2] == 1:
        xmin = max([xmin,l[i][0]])
    elif l[i][2] == 2:
        xmax = min([xmax,l[i][0]])
    elif l[i][2] == 3:
        ymin = max([ymin,l[i][1]])
    elif l[i][2] == 4:
        ymax = min([ymax,l[i][1]])
ans = max([(xmax - xmin)*(ymax - ymin),0])
print(ans)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
xmin = 0
ymin = 0
xmax = w
ymax = h
for i in range(n):
    if l[i][2] == 1:
        xmin = max([xmin,l[i][0]])
    elif l[i][2] == 2:
        xmax = min([xmax,l[i][0]])
    elif l[i][2] == 3:
        ymin = max([ymin,l[i][1]])
    else:
        ymax = min([ymax,l[i][1]])
ans = max([(xmax - xmin)*(ymax - ymin),0])
print(ans)

Submission status: Wrong Answer

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

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

for i in range(n):
    if a[i][2]==1:
        xmin=max([xmin,a[i][0]])
    elif a[i][2]==2:
        xmax=min([xmax,a[i][0]])
    elif a[i][2]==3:
        ymin=max([ymin,a[i][1]])
    else:
        ymax=min([ymax,a[i][1]])
ans=max([(xmax-xmin)*(ymax-ymin),0])
print(ans)

Submission status: Wrong Answer

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

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

s1 = 0
s2 = w
t1 = 0
t2 = h

for i in range(n):
    if li[i][2] == 1:
        s1 = li[i][0]
    if li[i][2] == 2:
        s2 = li[i][0]
    if li[i][2] == 3:
        t1 = li[i][1]
    if li[i][2] == 4:
        t2 = li[i][1]

if s2-s1 < 0 or t2-t1 < 0:
    print(0)
    exit()
        
ans = (s2-s1) * (t2-t1)

print(ans if ans > 0 else 0)

Submission status: Wrong Answer

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

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

s1 = 0
s2 = w
t1 = 0
t2 = h

for i in range(n):
    if li[i][2] == 1:
        s1 = li[i][0]
    if li[i][2] == 2:
        s2 = li[i][0]
    if li[i][2] == 3:
        t1 = li[i][1]
    if li[i][2] == 4:
        t2 = li[i][1]
        
ans = (s2-s1) * (t2-t1)

print(ans if ans > 0 else 0)

Submission status: Wrong Answer

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

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

x = p1[0]-p0[0]
y = p1[1]-p0[1]
if x < 0:
    x = 0
if y < 0:
    y = 0

print(x * y)

Submission status: Wrong Answer

Solution code:
import numpy as np
row = input().split()
W = int(row[0])
H = int(row[1])
N = int(row[2])
row2 = [input().split() for i in range(N)]
f = np.vectorize(int)
x = f(row2)
white = [0,0,W,H]
for i in x:
    if i[2] == 1 and white[0] < i[0]:
        white[0] = i[0]
    if i[2] == 2 and white[2] > i[0]:
        white[2] = i[0]
    if i[2] == 3 and white[1] < i[1]:
        white[1] = i[1]
    if i[2] == 4 and white[3] > i[1]:
        white[3] = i[1]
square = (white[2]-white[0])*(white[3]-white[1])
if square < 0:
    square = 0
print(square)

Submission status: Wrong Answer

Solution code:
import numpy as np
row = input().split()
W = int(row[0])
H = int(row[1])
N = int(row[2])
row2 = [input().split() for i in range(N)]
f = np.vectorize(int)
x = f(row2)
white = [0,0,W,H]
for i in x:
    if i[2] == 1:
        white[0] = i[0]
    if i[2] == 2:
        white[2] = i[0]
    if i[2] == 3:
        white[1] = i[1]
    if i[2] == 4:
        white[3] = i[1]
square = (white[2]-white[0])*(white[3]-white[1])
if square < 0:
    square = 0
print(square)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

for i in range(a[2]):
  b = list(map(int,input().split()))
  if b[2]==1:
    a[0]-=b[0]
  elif b[2]==2:
    a[0]-=a[0]-b[0]
  elif b[2]==3:
    a[1]-=b[1]
  else:
    a[1]-=a[1]-b[1]
else:
  print(a[0]*a[1])

Submission status: Wrong Answer

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

    up = [i[1] for i in x_y_a if i[2] == 4]+[h]
    down = [i[1] for i in x_y_a if i[2] == 3]+[0]
    left = [i[0]for i in x_y_a if i[2] == 1]+[0]
    right = [i[0] for i in x_y_a if i[2] == 2]+[w]
    ans = max((min(up)-max(down))*(min(right)-max(left)),0)
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    w,h,n = map(int,input().split(' '))
    up = h
    down = 0
    left = 0
    right = w

    for i in range(n):
        x,y,a = map(int,input().split(' '))
        if a == 1 and x > left:
            left = x
        elif a == 2 and x < right:
            right = x
        elif a == 3 and y > down:
            down = y
        elif a == 4 and y < up:
            up = y
    ans = max((right - left)*(up - down),0)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

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

        if a == 1:
            x_min = max(x_min, x)
        elif a == 2:
            x_max = min(x_max, x)
        elif a == 3:
            y_min = max(y_max, y)
        elif a == 4:
            y_max = min(y_max, y)

    print(max(0, x_max - x_min) * max(0, y_max - y_min))

        # 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
        # 
        # if (x_max <= x_min) or (y_max <= y_min):
        #     print(0)
        #     return

    # print((x_max - x_min) * (y_max - y_min))

if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

    for n 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

        if (x_max <= x_min) or (y_max <= y_min):
            print(0)
            return

    print((x_max - x_min) * (y_max - y_min))

if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
def main():
    x_max, y_max, n = map(int, input().split())
    x_min, y_min = 0, 0

    for n 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) or (y_max <= y_min):
            print(0)
            return

    print((x_max - x_min) * (y_max - y_min))

if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x1=0
y1=0
x2=w
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(x2,x)
    elif a==3:
        y1=max(y1,y)
    elif a==4:
        y2=min(y2,y)
print(max(0,(x2-x1)*(y2-y1)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x_min = 0
y_min = 0
x_max = W
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

width = x_max - x_min
height = y_max - y_min
if width > 0 and height > 0:
    print(width * height)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
o1=0
o2=0
oo1=0
oo2=0
w,h,n=map(int,input().split())
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        oo1=max(o1+x,oo1)
    elif a==2:
        w=min(x,w)
    elif a==3:
        oo2=max(o2+y,oo2)
    else:h=min(y,h)
if o1>=w or o2>=h:
    print(0)
else:print((w-oo1)*(h-oo2))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
# B/T: bottom/top, L/R: left/right
BL = [0,0]
BR = [W,0]
TL = [0,H]
TR = [W,H]
for i in range(N):
  assert BL[0] == TL[0] 
  assert TL[1] == TR[1]
  assert TR[0] == BR[0]
  assert BL[1] == BR[1]
  x, y, a = map(int, input().split())
  if a==1:
    # cut left
    new_x = max(BL[0], x)
    BL = [new_x, BL[1]]
    TL = [new_x, TL[1]]
  elif a==2:
    # cut right
    new_x = min(BR[0], x)
    BR = [new_x, BR[1]]
    TR = [new_x, TR[1]]
  elif a==3:
    # cut bottom
    new_y = max(BL[1], y)
    BL = [BL[0], new_y]
    BR = [BR[0], new_y]
  else:
    assert a==4
    # cut top
    new_y = min(TL[1], y)
    TL = [TL[0], new_y]
    TR = [TR[0], new_y]
print(str(max(0, int((BR[0]-BL[0])*(TL[1]-BL[1])))))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
# B/T: bottom/top, L/R: left/right
BL = [0,0]
BR = [W,0]
TL = [0,H]
TR = [W,H]
for i in range(N):
  assert BL[0] == TL[0] 
  assert TL[1] == TR[1]
  assert TR[0] == BR[0]
  assert BL[1] == BR[1]
  x, y, a = map(int, input().split())
  if a==1:
    # cut left
    new_x = max(BL[0], x)
    BL = [new_x, BL[1]]
    TL = [new_x, TL[1]]
  elif a==2:
    # cut right
    new_x = min(BR[0], x)
    BR = [new_x, BR[1]]
    TR = [new_x, TR[1]]
  elif a==3:
    # cut bottom
    new_y = max(BL[1], y)
    BL = [BL[0], new_y]
    BR = [BR[0], new_y]
  else:
    assert a==4
    # cut top
    new_y = min(TL[1], y)
    TL = [TL[0], new_y]
    TR = [TR[0], new_y]
print(str(max(0,(BR[0]-BL[0])*(TL[1]-BL[1]))))

Submission status: Wrong Answer

Solution code:
w, h, n = [ int(v) for v in input().split() ]
u, d, l, r = h, 0, 0, w

for i in range(n):
    x, y, a = [ int(v) for v in input().split() ]
    if a == 1 and x <= r:
        r = x
    elif a == 2 and x >= l:
        l = x
    elif a == 3 and y >= d:
        d = y
    elif a == 4 and y <= u:
        u = y



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

Submission status: Wrong Answer

Solution code:

w, h, n = [ int(v) for v in input().split() ]
u_list = []
l_list = []
r_list = []
d_list = []

for i in range(n):
    x, y, a = [ int(v) for v in input().split() ]
    if a == 1:
        r_list.append(x)
    elif a == 2:
        l_list.append(x)
    elif a == 3:
        d_list.append(y)
    elif a == 4:
        u_list.append(y)

u, d, l, r = h, 0, 0, w
if u_list != []:
    u = sorted(u_list)[-1]
if d_list != []:
    d = sorted(d_list)[0]
if l_list != []:
    l = sorted(l_list)[0]
if r_list != []:
    r = sorted(r_list)[-1]

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

Submission status: Wrong Answer

Solution code:
w, h, n = [ int(v) for v in input().split() ]
u_list = []
l_list = []
r_list = []
d_list = []

for i in range(n):
    x, y, a = [ int(v) for v in input().split() ]
    if a == 1:
        l_list.append(x)
    elif a == 2:
        r_list.append(x)
    elif a == 3:
        d_list.append(y)
    elif a == 4:
        u_list.append(y)

u, d, l, r = h, 0, 0, w
if u_list != []:
    u = sorted(u_list)[-1]
if d_list != []:
    d = sorted(d_list)[0]
if l_list != []:
    l = sorted(l_list)[0]
if r_list != []:
    r = sorted(r_list)[-1]

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

Submission status: Wrong Answer

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

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

    if a == 1:
        W0 = max(W0, x)
    elif a == 2:
        W = min(W, x)
    elif a == 3:
        H0 = max(H0, y)
    else:
        H = min(H, y)

ans = (W - W0) * (H - H0)
if ans < 0:
    ans = 0

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

W, H, N = map(int, input().split())
l = d = 0
u = H
r = W
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        l = max(x, l)
    if a == 2:
        r = min(x, r)
    if a == 3:
        d = max(y, d)
    if a == 4:
        u = min(y, u)

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

Submission status: Wrong Answer

Solution code:
import sys

W, H, N = map(int, input().split())
l = d = 0
u = H
r = W
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        l = max(x, l)
    if a == 2:
        r = min(x, r)
    if a == 3:
        d = max(y, d)
    if a == 4:
        u = min(y, u)

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

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
x1,y1 = 0, 0
x2, y2 = w, h
for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x1 = max(x1, x)
    if a == 2:
        x2 = min(x2, x)
    if a == 3:
        y1 = max(y1, y)
    if a == 4:
        y2 = min(y2, y)
#print("{0} {1} {2} {3}".format(str(x1), str(y1), str(x2), str(y2)))
print(max((x2 - x1) * (y2 - y1), 0))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
x1,y1 = 0, 0
x2, y2 = w, h
for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x1 = max(x1, x)
    if a == 2:
        x2 = min(x2, x)
    if a == 3:
        y1 = max(y1, y)
    if a == 4:
        y2 = min(y2, y)
#print("{0} {1} {2} {3}".format(str(x1), str(y1), str(x2), str(y2)))
print((x2 - x1) * (y2 - y1) if (x2 - x1) * (y2 - y1) > 0 else 0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
W, H, N = map(int, raw_input().split())

x_arr = [0] * N
y_arr = [0] * N
a_arr = [0] * N
for idx in range(0, N):
  x_arr[idx], y_arr[idx], a_arr[idx] = map(int, raw_input().split())

x_zero = 0
x_inf = W
y_zero = 0
y_inf = H
a_max_min = [x_zero, x_inf, y_zero, y_inf]

for idx in range(0, N):
  a_tmp = a_arr[idx]
  if a_tmp == 1:
    a_max_min[0] = max(a_max_min[0], x_arr[idx])
  elif a_tmp == 2:
    a_max_min[1] = min(a_max_min[1], x_arr[idx])
  elif a_tmp == 3:
    a_max_min[2] = max(a_max_min[2], y_arr[idx])
  elif a_tmp == 4:
    a_max_min[3] = min(a_max_min[3], y_arr[idx])

answer = max(0, (a_max_min[1] - a_max_min[0]) * (a_max_min[3] - a_max_min[2]))

print(answer)

# https://atcoder.jp/contests/abc047/tasks/abc047_b

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
W, H, N = map(int, raw_input().split())

x_arr = [0] * N
y_arr = [0] * N
a_arr = [0] * N
for idx in range(0, N):
  x_arr[idx], y_arr[idx], a_arr[idx] = map(int, raw_input().split())

x_zero = 0
x_inf = W
y_zero = 0
y_inf = H
a_max_min = [x_zero, x_inf, y_zero, y_inf]

for idx in range(0, N):
  a_tmp = a_arr[idx]
  if a_tmp == 1:
    a_max_min[0] = max(a_max_min[0], x_arr[idx])
  elif a_tmp == 2:
    a_max_min[1] = min(a_max_min[1], x_arr[idx])
  elif a_tmp == 3:
    a_max_min[2] = max(a_max_min[2], y_arr[idx])
  elif a_tmp == 4:
    a_max_min[3] = min(a_max_min[3], y_arr[idx])

answer = max(0, (a_max_min[1] - a_max_min[0]) * (a_max_min[3] - a_max_min[2]), 0)

print(answer)

# https://atcoder.jp/contests/abc047/tasks/abc047_b

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
W, H, N = map(int, raw_input().split())

x_arr = [0] * N
y_arr = [0] * N
a_arr = [0] * N
for idx in range(0, N):
  x_arr[idx], y_arr[idx], a_arr[idx] = map(int, raw_input().split())

x_zero = 0
x_inf = W
y_zero = 0
y_inf = H
a_max_min = [x_zero, x_inf, y_zero, y_inf]

for idx in range(0, N):
  a_tmp = a_arr[idx]
  if a_tmp == 1:
    a_max_min[0] = max(a_max_min[0], x_arr[idx])
  elif a_tmp == 2:
    a_max_min[1] = min(a_max_min[1], x_arr[idx])
  elif a_tmp == 3:
    a_max_min[2] = max(a_max_min[2], y_arr[idx])
  elif a_tmp == 4:
    a_max_min[3] = min(a_max_min[3], y_arr[idx])

answer = (a_max_min[1] - a_max_min[0]) * (a_max_min[3] - a_max_min[2])

print(answer)

Submission status: Wrong Answer

Solution code:
xmax,ymax,N=map(int,input().split())
xmin=0
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,(xmax-xmin)*(ymax-ymin)))

Submission status: Wrong Answer

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

W, H, N = mi()

#H[0], H[1]が白い部分の左端～右端を表す
H = [0, H]
W = [0, W]

for i in range(N):
  x, y, a = mi()
  if a == 1:
    W[0] = max(x,W[0])
  elif a == 2:
    W[1] = min(x,W[1])
  elif a == 3:
    H[0] = max(y,H[0])
  else:
    H[1] = min(y,H[1])

print(max((H[1]-H[0])*(W[1]-W[0]),0))

Submission status: Wrong Answer

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

xys = [[0] * (W + 1) for _ in range(H + 1)] # 塗りつぶし判定用

for xya in xyas:
  x = xya[0]
  y = xya[1]
  a = xya[2]
  
  xrange = list() # 塗りつぶすx範囲
  yrange = list() # 塗りつぶすy範囲
  if a == 1:
    xrange = range(x + 1)
    yrange = range(H + 1)
  elif a == 2:
    xrange = range(x, W + 1)
    yrange = range(H + 1)
  elif a == 3:
    xrange = range(W + 1)
    yrange = range(y + 1)
  else:
    xrange = range(W + 1)
    yrange = range(y, H + 1)
  for i in yrange:
    for j in xrange:
      xys[i][j] = 1
cnt = 0
for i in range(H + 1):
  for j in range(W + 1):
    if xys[i][j] == 0:
      cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
data=[list(map(int,input().split())) for i in range(N)]
_W=0
_H=0
for i in data:
    if i[2]==1:
        _W=max(i[0],_W)
    if i[2]==2:
        W=min(W,i[0])
    if i[2]==3:
        _H=max(i[1],_H)
    if i[2]==4:
        H=min(H,i[1])

if W-_W<=0 or H-_H<=0:
    print(0)
a=int((W-_W)*(H-_H))
if a>0:
    print(a)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
data=[list(map(int,input().split())) for i in range(N)]
_W=0
_H=0
for i in data:
    if i[2]==1:
        _W=max(i[0],_W)
    if i[2]==2:
        W=min(W,i[0])
    if i[2]==3:
        _H=max(i[1],_H)
    if i[2]==4:
        H=min(H,i[1])

if W-_W<0 or H-_H<0:
    print(0)
a=int((W-_W)*(H-_H))
if a>0:
    print(a)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
data=[list(map(int,input().split())) for i in range(N)]
_W=0
_H=0
for i in data:
    if i[2]==1:
        _W=max(i[0],_W)
    if i[2]==2:
        W=min(W,i[0])
    if i[2]==3:
        _H=max(i[1],_H)
    if i[2]==4:
        H=min(H,i[1])

a=int((W-_W)*(H-_H))
if a>0:
    print(a)
else:
    print(0)

Submission status: Wrong Answer

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


x_min=0
y_min=0

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

    if a==1:
        x_min=max(x_min,x)

    elif a==2:
        w=min(x,w)

    elif a==3:
        y_min=max(y_min,y)

    elif a==4:
        h=min(y,h)

white=(w-x_min)*(h-y_min)

if white>0:
  print(white)
  
else:
  print("0")

Submission status: Wrong Answer

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

x_r = [w]
x_l = [0]
y_r = [h]
y_l = [0]
for i in range(n):
    if para[i][2] == 1 : x_l.append(para[i][0])
    elif para[i][2] == 2 :x_r.append(para[i][0])
    elif para[i][2] == 3 : y_l.append(para[i][1])
    else: y_r.append(para[i][1])
x = min(x_r)-max(x_l)
y = min(y_r) - max(y_l)

print("{}".format(x*y))

Submission status: Wrong Answer

Solution code:
# B問題
W, H , N = map(int, input().split())
xya = []
for i in range(N):
    xya.append(list(map(int, input().split())))
"""
面積を求めるには4点分かれば良い
4点の位置を調べる
"""
# 初期値
A = [0, 0]
B = [W, 0]
C = [W, H]
D = [0, H]

# 点A, B, C, Dを移動させる関数
def drow(x, y, a):
    if a == 1:
        A[0] = x
        D[0] = x
    elif a == 2:
        B[0] = x
        C[0] = x
    elif a == 3:
        A[1] = y
        B[1] = y
    elif a == 4:
        C[1] = y
        D[1] = y

for i in range(N):   # 入力された各点を移動させる
    drow(xya[i][0], xya[i][1], xya[i][2])

if A[0] >= B[0] or A[1] >= D[1]:   # 面積が0になる時
    print(0)
else:
    print((B[0] - A[0])*(D[1] - A[1]))

Submission status: Wrong Answer

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

min_x=0
min_y=0

for i 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)

    elif a==4:
        h=min(h,y)

white=int((w-min_x)*(h-min_y))

if white>0:
    print(white)

else:
    print("0")

Submission status: Wrong Answer

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

min_x=0
min_y=0

for i 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)

    elif a==4:
        h=min(h,y)

white=(w-min_x)*(h-min_y)

if white>0:
    print(white)

else:
    print("0")

Submission status: Wrong Answer

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

min_x=0
min_y=0

for i 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)

white=(w-min_x)*(h-min_y)

if white>0:
    print(white)

else:
    print("0")

Submission status: Wrong Answer

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

min_x=0
min_y=0

for i 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)

white=(w-min_x)*(h-min_y)

if white>0:
    print(white)

else:
    print("0")

Submission status: Wrong Answer

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

min_x=0
min_y=0

for i 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)

white=(w-min_x)*(h-min_y)
print(white)

Submission status: Wrong Answer

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

min_x=0
min_y=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

white=(w-min_x)*(h-min_y)

if white>0:
    print(white)

else:
    print("0")

Submission status: Wrong Answer

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

nums=[]

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

white=w*h

for i in range(len(nums)):
    w=w
    h=h

    if nums[i][2]==1:
        w=w-nums[i][0]
        
    elif nums[i][2]==2:
        w=nums[i][0]
        
    elif nums[i][2]==3:
        h=h-nums[i][1]
    
    elif nums[i][2]==4:
        h=nums[i][1]
        
    
    white=w*h
if white>0:
    print(white)

else:
    print("0")