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:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    W,H,N = MI()
    bottom = 0
    top = H
    left = 0
    right = W
    print(right)
    for i in range(N):
        a,b,c = MI()
        if c==1:
            left = max(left,a)
        if c==2:
            right = min(right,a)
        if c==3:
            bottom = max(bottom, b)
        if c==4:
            top = min(top, b)
    print((right-left)*(top-bottom))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

w0 = 0
h0 = 0
for i in range(n):
    if xya[i][2] == 1:
        w0 = max(w0,xya[i][0])
    elif xya[i][2] == 2:
        w = min(w,xya[i][0])
    elif xya[i][2] == 3:
        h0 = max(h0,xya[i][1])
    else:
        h = min(h,xya[i][1])
        
print(max(0, (w-w0) * (h-h0)))

Submission status: Wrong Answer

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

w0 = 0
h0 = 0
for i in range(n):
    if xya[i][2] == 1:
        w0 = xya[i][0]
    elif xya[i][2] == 2:
        w = xya[i][0]
    elif xya[i][2] == 3:
        h0 = xya[i][1]
    else:
        h = xya[i][1]

print(max(0,(w-w0) * (h-h0)))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(n)]
lx = 0
rx = w
ly = 0
ry = h
for x,y,a in xya:
  if a == 1:
    lx = x
  elif a == 2:
    rx = x
  elif a == 3:
    ly = y
  else:
    ry = y
ans = max(0,rx-lx) * max(0,ry-ly)
print(ans)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(n)]
lx = 0
rx = w
ly = 0
ry = h
for x,y,a in xya:
  if a == 1:
    lx = x
  elif a == 2:
    rx = x
  elif a == 3:
    ly = y
  else:
    ry = y
ans = w * h - max(0,rx-lx) * max(0,ry-ly)
print(ans)

Submission status: Wrong Answer

Solution code:
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


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

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

minx = 0
maxx = w
miny = 0
maxy = h


for i in range(n):
	if   l[i][2] == 1:
		if minx < l[i][0]:
			minx = l[i][0]

	elif l[i][2] == 2:
		if maxx > l[i][0]:
			maxx = l[i][0]
	
	elif l[i][2] == 3:
		if miny < l[i][1]:
			miny = l[i][1]	
	
	elif l[i][2] == 4:
		if maxy > l[i][1]:
			maxy = l[i][1]
			
ans = (maxx-minx)*(maxy-miny)			
			
print( ans )

Submission status: Wrong Answer

Solution code:
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


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

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

minx = 0
maxx = w
miny = 0
maxy = h


for i in range(n):
	if   l[i][2] == 1:
		if minx < l[i][0]:
			minx = l[i][0]

	elif l[i][2] == 2:
		if maxx > l[i][0]:
			maxx = l[i][0]
	
	elif l[i][2] == 3:
		if miny < l[i][1]:
			miny = l[i][1]	
	
	elif l[i][2] == 4:
		if maxy > l[i][1]:
			maxy = l[i][1]
			
ans = (maxx-minx)*(maxy-miny)			
			
print( ans if ans >=0 else 0)

Submission status: Wrong Answer

Solution code:
w,h,n=[int(i) for i in input().split()]
x_u=w
y_u=h
x_l=0
y_l=0
for i in range(n):
    x,y,a=[int(i) for i in input().split()]
    if(a==1):
        x_l=x
    elif(a==2):
        x_u=x
    elif(a==3):
        y_l=y
    elif(a==4):
        y_u=y
s=(x_u-x_l)*(y_u-y_l)
if(s<0):
    print(0)
else:
    print(s)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
minW = 0
maxW = W
minH = 0
maxH = H
for _ in range(N):
    x, y, a = map(int, input().split()) 
    if a == 1:
      if minW < x:
        minW = x
    elif a == 2:
      if maxW > x:
        maxW = x
    elif a == 3:
      if minH < y:
        minH = y
    elif a == 4:
      if maxH > y:
        maxH = y
        
    W = minW - maxW
    H = minH - maxH

if not W * H < 0:
  print(W * H)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
minW = 0
maxW = W
minH = 0
maxH = H
for _ in range(N):
    x, y, a = map(int, input().split()) 
    if a == 1:
      if minW < x:
        minW = x
    elif a == 2:
      if maxW > x:
        maxW = x
    elif a == 3:
      if minH < y:
        minH = y
    elif a == 4:
      if maxH > y:
        maxH = y
        
    W = maxW - minW
    H = maxH - minH

if not W * H < 0:
  print(W * H)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int ,input().split())
e = [[int(i) for i in input().split()] for i in range(n)]  
menseki=w*h
h1=h
w1=w
xmax=w
xmin=0
ymax=h
ymin=0

for i in range(n):
    if e[i][2]==1:
        if  xmin<e[i][0] and h>=e[i][0]:
            black=e[i][0] * h1
            menseki-=black
            w1-=e[i][0]   
            xmin=e[i][0] 
    if e[i][2]==2:
        if xmax>e[i][0] and 0<=e[i][0]:
            black=(w-e[i][0]) * h1
            menseki-=black
            w1=(w1-(w-e[i][0]))
            xmax=e[i][0] 
    if e[i][2]==3:
        if  ymin<e[i][1]and w>=e[i][1]:
            black=e[i][1] * w1
            menseki-=black
            h1-=e[i][1]
            ymin=e[i][1]
    if e[i][2]==4:        
        if ymax>e[i][1] and 0<=e[i][1]:
            black=(h-e[i][1]) * w1
            menseki-=black
            h1=(h1-(h-e[i][1]))
            ymax=e[i][1]
if menseki<0:
    print("0")
else:    
    print (menseki)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int ,input().split())
e = [[int(i) for i in input().split()] for i in range(n)]  
menseki=w*h
h1=h
w1=w
xmax=w
xmin=0
ymax=h
ymin=0

for i in range(n):
    if e[i][2]==1:
        if  xmin<e[i][0]:
            black=e[i][0] * h1
            menseki-=black
            w1-=e[i][0]   
            xmin=e[i][0] 
    if e[i][2]==2:
        if xmax>e[i][0] :
            black=(w-e[i][0]) * h1
            menseki-=black
            w1=(w1-(w-e[i][0]))
            xmax=e[i][0] 
    if e[i][2]==3:
        if  ymin<e[i][1]:
            black=e[i][1] * w1
            menseki-=black
            h1-=e[i][1]
            ymin=e[i][1]
    if e[i][2]==4:        
        if ymax>e[i][1] :
            black=(h-e[i][1]) * w1
            menseki-=black
            h1=(h1-(h-e[i][1]))
            ymax=e[i][1]
if menseki<0:
    print("0")
else:    
    print (menseki)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int ,input().split())
e = [[int(i) for i in input().split()] for i in range(n)]  
menseki=w*h
h1=h
w1=w
xmax=w
xmin=0
ymax=h
ymin=0

for i in range(n):
    if e[i][2]==1:
        if  xmin<e[i][0]:
            black=e[i][0] * h1
            menseki-=black
            w1-=e[i][0]   
            xmin=e[i][0] 
    if e[i][2]==2:
        if xmax>e[i][0] :
            print(h1)
            black=(w-e[i][0]) * h1
            menseki-=black
            w1=(w1-(w-e[i][0]))
            xmax=e[i][0] 
    if e[i][2]==3:
        if  ymin<e[i][1]:
            black=e[i][1] * w1
            menseki-=black
            h1-=e[i][1]
            ymin=e[i][1]
    if e[i][2]==4:        
        if ymax>e[i][1] :
            black=(h-e[i][1]) * w1
            menseki-=black
            h1=(h1-(h-e[i][1]))
            ymax=e[i][1]
    print(menseki)
if menseki<0:
    print("0")
else:    
    print (menseki)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int ,input().split())
e = [[int(i) for i in input().split()] for i in range(n)]  
menseki=w*h
h1=h
w1=w
xmax=w
xmin=0
ymax=h
ymin=0

for i in range(n):
    if e[i][2]==1:
        if xmax>e[i][0] and xmin<e[i][0]:
            black=e[i][0] * h1
            menseki-=black
            w1-=e[i][0]   
            xmin=e[i][0] 
    if e[i][2]==2:
        if xmax>e[i][0] and xmin<e[i][0]:
            print(h1)
            black=(w-e[i][0]) * h1
            menseki-=black
            w1=(w1-(w-e[i][0]))
            xmax=e[i][0] 
    if e[i][2]==3:
        if ymax>e[i][1] and ymin<e[i][1]:
            black=e[i][1] * w1
            menseki-=black
            h1-=e[i][1]
            ymin=e[i][1]
    if e[i][2]==4:        
        if ymax>e[i][1] and ymin<e[i][1]:
            black=(h-e[i][1]) * w1
            menseki-=black
            h1=(h1-(h-e[i][1]))
            ymax=e[i][1]
    print(menseki)
if menseki<0:
    print("0")
else:    
    print (menseki)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int ,input().split())
e = [[int(i) for i in input().split()] for i in range(n)]  
menseki=w*h
h1=h
w1=w
x=0
y=0
for i in range(n):
    if e[i][2]==1:
        black=e[i][0] * h1
        menseki-=black
        w1-=e[i][0]
    if e[i][2]==2:
        black=(w-e[i][0]) * h1
        menseki-=black
        w1-=(w1-(w-e[i][0]))
    if e[i][2]==3:
        black=e[i][1] * w1
        menseki-=black
        h1=e[i][1]
    if e[i][2]==4:
        black=(h-e[i][1]) * w1
        menseki-=black
        h1=(h1-(h-e[i][1]))
if menseki<0:
    print("0")
else:    
    print (menseki)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int ,input().split())
e = [[int(i) for i in input().split()] for i in range(n)]  
menseki=w*h
h1=h
w1=w
x=0
y=0
for i in range(n):
    if e[i][2]==1:
        black=e[i][0] * h1
        menseki-=black
        w1-=e[i][0]
    if e[i][2]==2:
        print(h1)
        black=(w-e[i][0]) * h1
        menseki-=black
        w1-=(w1-(w-e[i][0]))
    if e[i][2]==3:
        black=e[i][1] * w1
        menseki-=black
        h1=e[i][1]
    if e[i][2]==4:
        black=(h-e[i][1]) * w1
        menseki-=black
        h1=(h1-(h-e[i][1]))
    print(menseki)
if menseki<0:
    print("0")
else:    
    print (menseki)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int ,input().split())
e = [[int(i) for i in input().split()] for i in range(n)]  
menseki=w*h
x=0
y=0
for i in range(n):
    if e[i][2]==1:
        black=e[i][0] * h
        menseki-=black
        w-=e[i][0]
    if e[i][2]==2:
        black=(w-e[i][0]) * h
        menseki-=black
        w-=(w-e[i][0])
    if e[i][2]==3:
        black=e[i][1] * w
        menseki-=black
        h=e[i][1]
    if e[i][2]==4:
        black=(h-e[i][1]) * w
        menseki-=black
        h=(h-e[i][1])
print (menseki)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W,H,N = map(int,input().split())
mat = [list(map(int,input().split())) for i in range(N)]
x = [0,W]
y = [0,H]
for i in range(N):
    if mat[i][2] == 1:
        x[0] = mat[i][0]
    if mat[i][2] == 2:
        x[1] = mat[i][0]
    if mat[i][2] == 3:
        y[0] = mat[i][1]
    if mat[i][2] == 4:
        y[1] = mat[i][1]
print(max([(x[1]-x[0])*(y[1]-y[0]),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)
print((w-min_x)*(h-min_y) if (w-min_x)*(h-min_y) > 0 else 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 and min_x < x:
        min_x = x  
    elif a == 2 and x < w:
        w = x
    elif a == 3 and min_y < y:
        min_y = y
    elif a == 4 and y < h:
        h = y
print((w-min_x)*(h-min_y) if (w-min_x)*(h-min_y) > 0 else 0)

Submission status: Wrong Answer

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

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

x_lb,x_ub,y_lb,y_ub = 0,W,0,H

for x,y,a in XYA:
    if a==1:
        x_lb = max(x_lb,x)
    elif a==2:
        x_ub = min(x_ub,x)
    elif a==3:
        y_lb = max(y_lb,y)
    else:
        y_ub = min(y_ub,y)

print(max((x_ub - x_lb)*(y_ub - y_lb), 0))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xyalist = [tuple(map(int, input().split())) for _ in range(N)]
points = [[0, 0], [W, H]]
for x, y, a in xyalist:
    if a == 1:
        if x > points[0][0]:
            points[0][0] = x
    elif a == 2:
        if x < points[1][0]:
            points[1][0] = x
    elif a == 3:
        if y > points[0][1]:
            points[0][1] = y
    elif a == 4:
        if y < points[1][1]:
            points[1][1] = y
area = (points[1][0] - points[0][0]) * (points[1][1] - points[0][1])
print(area if area > 0 else 0)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xyalist = [tuple(map(int, input().split())) for _ in range(N)]
points = [[0, 0], [W, H]]
for x, y, a in xyalist:
    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)

Submission status: Wrong Answer

Solution code:
W,H,N = map(int,input().split())
Xl=0
Xr=W
Yu=0
Yh=H

for i in range(N):
    Xt,Yt,At = map(int,input().split())
    if((At==1)and(Xl<Xt)):
        Xl=Xt
    elif((At==2)and(Xr>Xt)):
        Xr=Xt
    elif((At==3)and(Yu<Yt)):
        Yu=Yt
    elif(Yh>Yt):
        Yh=Yt

if((Xr<=Xl)or(Yh<=Yu)):
    print("0")
else:
    print((Xr-Xl)*(Yh-Yu))

Submission status: Wrong Answer

Solution code:
W,H,N = map(int,input().split())
Xl=0
Xr=W
Yu=0
Yh=H

for i in range(N):
    Xt,Yt,At = map(int,input().split())
    if(At==1):
        Xl=Xt
    elif(At==2):
        Xr=Xt
    elif(At==3):
        Yu=Yt
    else:
        Yh=Yt

if((Xr<=Xl)or(Yh<=Yu)):
    print("0")
else:
    print((Xr-Xl)*(Yh-Yu))

Submission status: Wrong Answer

Solution code:
W,H,N = map(int,input().split())
Xl=0
Xr=W
Yu=0
Yh=H
for i in range(N):
    Xt,Yt,At = map(int,input().split())
    if(At==1):
        Xl=Xt
    elif(At==2):
        Xr=Xt
    elif(At==3):
        Yu=Yt
    else:
        Yh=Yt

if((Xr<Xl)or(Yh<Yu)):
    print("0")
else:
    print((Xr-Xl)*(Yh-Yu))

Submission status: Wrong Answer

Solution code:
import numpy as np

W,H,N=[int(i) for i in input().split()]
lst=[]
for j in range(N):
    lst.append([int(i) for i in input().split()])
print(lst)

square=np.zeros(H*W,dtype=np.int64).reshape(H,W)
print(square)

for i in lst:
    x=i[0]
    y=i[1]
    a=i[2]
    if(a==1):
        for j in range(x):
            for k in range(H):
                square[k][j]=1
        #print(square)
    elif(a==2):
        for j in range(x,W):
            for k in range(H):
                square[k][j]=1
        #print(square)
    elif(a==3):
        for j in range(H-y,H):
            for k in range(W):
                square[j][k]=1
        #print(square)
    else:
        for j in range(H-y-1,-1,-1):
            for k in range(W):
                square[j][k]=1
        #print(square)

print(np.count_nonzero(square ==0))

Submission status: Wrong Answer

Solution code:
W, H ,N = map(int, input().split())
S = [list(map(int, input().split())) for i in range(N)]
A1=[i[0] for i in S if i[2]==1]
A2=[i[0] for i in S if i[2]==2]
A3=[i[1] for i in S if i[2]==3]
A4=[i[1] for i in S if i[2]==4]
if A1==[] and A2==[]:
    W_after=W
elif A1==[]:
    W_after=min(A2)
elif A2==[]:
    W_after=max(A1)
elif min(A2)<=max(A1):
    W_after=0
elif max(A1)<min(A2):
    W_after=min(A2)-max(A1)

if A3==[] and A4==[]:
    H_after=H
elif A3==[]:
    H_after=min(A4)
elif A4==[]:
    H_after=max(A3)
elif min(A4)<=max(A3):
    H_after=0
elif max(A3)<min(A4):
    H_after=min(A4)-max(A3)
print(H_after*W_after)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x_b=w
x_s=0
y_b=h
y_s=0
for i in range(1,n+1):
  x,y,a=map(int,input().split())
  if a==1:
    x_b=min(x,x_b)
  elif a==2:
    x_s=max(x,x_s)
  elif a==3:
    y_b=min(y,y_b)
  else:
    y_s=max(y,y_s)

if x_b<=x_s or y_b<=y_s:
  print(0)
else:  
  print((x_b-x_s)*(y_b-y_s))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x_b=w
x_s=0
y_b=h
y_s=0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x_b=min(x,x_b)
  elif a==2:
    x_s=max(x,x_s)
  elif a==3:
    y_b=min(y,y_b)
  else:
    y_s=max(y,y_s)

if x_b<=x_s or y_b<=y_s:
  print(0)
else:  
  print((x_b-x_s)*(y_b-y_s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = 0
r = w
d = 0
u = h

for x in li:
    if(x[-1] == 1):
        l = max(l, x[0])
    elif (x[-1] == 2):
        r = min(r, x[0])
    elif (x[-1] == 3):
        d = max(d, x[1])
    else:
        u = min(u, x[1])

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

Submission status: Wrong Answer

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

l = 0
r = w
d = 0
u = h

for x in li:
    if(x[-1] == 1):
        l = max(l, x[0])
    elif (x[-1] == 2):
        r = min(r, x[0])
    elif (x[-1] == 3):
        d = max(d, x[1])
    else:
        u = min(u, x[1])

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

Submission status: Wrong Answer

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

l = 0
r = w
d = 0
u = h

for x in li:
    if(x[-1] == 1):
        l = max(l, x[0])
    elif (x[-1] == 2):
        r = min(r, x[0])
    elif (x[-1] == 3):
        d = max(d, x[1])
    else:
        u = min(u, x[1])

print((r - l) * (u - d))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
lw=0;rw=w;lh=0;rh=h
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    lw=max(lw,x)
  elif a==2:
    rw=min(rw,x)
  elif a==3:
    lh=max(lh,y)
  else:
    rh=min(rh,y)
print(max((rh-lh)*(rw-lw),0))

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 _ 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)
else:
    print((x_max - x_min) * (y_max - y_min))

Submission status: Wrong Answer

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

for i in range(n):
  if L[i][2] == 1:
    for j in range(h):
      for k in range(w):
        if k < L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 2:
    for j in range(h):
      for k in range(w):
        if k >= L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 3:
    for j in range(h):
      for k in range(w):
        if j < L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 4:
    for j in range(h):
      for k in range(w):
        if j >= L[i][0]:
          Z[j][k] = 0
          
out = 0
for i in range(h):
  for j in range(w):
    out += Z[i][j]
print(out)

Submission status: Wrong Answer

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

print(Z)

for i in range(n):
  if L[i][2] == 1:
    for j in range(h):
      for k in range(w):
        if k < L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 2:
    for j in range(h):
      for k in range(w):
        if k >= L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 3:
    for j in range(h):
      for k in range(w):
        if j < L[i][0]:
          Z[j][k] = 0
  elif L[i][2] == 4:
    for j in range(h):
      for k in range(w):
        if j >= L[i][0]:
          Z[j][k] = 0
print(Z)
          
out = 0
for i in range(h):
  for j in range(w):
    out += Z[i][j]
print(out)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
tatemax=[h]
tatemin=[0]
yokomax=[w]
yokomin=[0]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        yokomin.append(x)      
    elif a==2:
        yokomax.append(x)       
    elif a==3:
        tatemin.append(y)    
    elif a==4:
        tatemax.append(y)
        
tate_max=min(tatemax)
tate_min=max(tatemin)
yoko_max=min(tatemax)
yoko_min=max(tatemin)
if tate_max<=tate_min or yoko_max<=yoko_min:
    print(0)
else:
    print((tate_max-tate_min)*(yoko_max-yoko_min))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
tatemax=[w]
tatemin=[0]
yokomax=[h]
yokomin=[0]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        tatemin.append(x)      
    elif a==2:
        tatemax.append(x)       
    elif a==3:
        yokomin.append(y)    
    elif a==4:
        yokomax.append(y)
tate_max=min(tatemax)
tate_min=max(tatemin)
yoko_max=min(tatemax)
yoko_min=max(tatemin)


if tate_max<=tate_min or yoko_max<=yoko_min:
    print(0)
    
else:
    print((tate_max-tate_min)*(yoko_max-yoko_min))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x = []
y = []
a = []
for _ in range(N):
    xx,yy,aa = map(int,input().split())
    x.append(xx)
    y.append(yy)
    a.append(aa)

rec = [[0,0],[W,H]]

for i in range(N):
    if a[i] == 1:
        if rec[0][0] <= x[i]:
            rec[0][0] = x[i]
    elif a[i] == 2:
        if rec[1][0] >= x[i]:
            rec[1][0] = x[i]
    elif a[i] == 3:
        if rec[0][1] <= y[i]:
            rec[0][1] = y[i]
    elif a[i] == 4:
        if rec[1][1] >= y[i]:
            rec[1][1] = y[i]

s = (rec[1][0]-rec[0][0])*(rec[1][1]-rec[0][1])
print(max(s,0))

Submission status: Wrong Answer

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

x = []
y = []
a = []
for _ in range(N):
    xx,yy,aa = map(int,input().split())
    x.append(xx)
    y.append(yy)
    a.append(aa)

rec = [[0,0],[W,0],[W,H],[0,H]]

for i in range(N):
    if a[i] == 1:
        if rec[0][0] <= x[i]:
            rec[0][0] = x[i]
            rec[3][0] = x[i]
    elif a[i] == 2:
        if rec[1][0] >= x[i]:
            rec[1][0] = x[i]
            rec[2][0] = x[i]
    elif a[i] == 3:
        if rec[0][1] <= y[i]:
            rec[0][1] = y[i]
            rec[1][1] = y[i]
    elif a[i] == 4:
        if rec[3][1] >= y[i]:
            rec[2][1] = y[i]
            rec[3][1] = y[i]

s = (rec[2][0]-rec[0][0])*(rec[2][1]-rec[0][1])
print(max(s,0))

Submission status: Wrong Answer

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

w = L[0]
h = L[1]
n = L[2]

X = list(range(w+1))
Y = list(range(h+1))
X_1 = [0]
Y_1 = [0]
X_2 = [w]
Y_2 = [h]
for i in range(n):
  li = list(map(int,input().split()))
  if li[2] == 1 and li[0] > max(X_1):
    X =  [n for n in X if n >= li[0]]
    X_1.append(li[0])
  elif li[2] == 2 and li[0] < min(X_2):
    X =  [n for n in X if n <= li[0]]
    X_2.append(li[0])
    
  elif li[2] == 3 and li[1] > max(Y_1):
    Y =  [n for n in Y if n >= li[1]]
    Y_1.append(li[1])
  elif li[2] == 4 and li[1] < min(Y_2):
    Y =  [n for n in Y if n <= li[1]]
    Y_2.append(li[1])
if X == [] or Y == []:
  print(0)
else:
  if X[0] == 0:
    X.remove(0)
  if Y[0] == 0:
    Y.remove(0)
  print((max(X)-min(X))*(max(Y)-min(Y)))

Submission status: Wrong Answer

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

X=[0,W]
Y=[0,H]

for i in range(N):
    if XYA[i][2]==1:
        X[0]=max(X[0],XYA[i][0])
    elif XYA[i][2]==2:
        X[1]=min(X[1],XYA[i][0])
    elif XYA[i][2]==3:
        Y[0]=max(Y[0],XYA[i][1])
    else:
        Y[1]=min(Y[1],XYA[i][1])

print(max((X[1]-X[0])*(Y[1]-Y[0]),0))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int,input().split())
#白い領域の端
l = 0
r = W
u = H
d = 0
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        l = max(x,l)
    elif a == 2:
        r = min(x,r,W)
    elif a == 3:
        d = max(y,d)
    else:
        u = min(y,u,H)
print(max(0,(r-l)*(u-d)))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int,input().split())
l = 0
r = W
u = H
d = 0
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        l = max(x,l)
    elif a == 2:
        r = min(x,r)
    elif a == 3:
        d = max(y,d)
    else:
        u = min(y,u)
if (r-l)*(u-d) >= 0:
    print((r-l)*(u-d))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def main():
    W, H, N = map(int, input().split())
    lx = 0
    rx = W
    by = 0
    ty = H

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

        if a == 1:
            lx = max(x, lx)
        if a == 2:
            rx = min(x, W, rx)
        if a == 3:
            by = max(y, by)
        if a == 4:
            ty = min(y, H, ty)

    print(max(0, (rx-lx)*(ty-by)))


main()

Submission status: Wrong Answer

Solution code:
def main():
    W, H, N = map(int, input().split())
    lx = 0
    rx = W
    by = 0
    ty = H

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

        if a == 1:
            lx = x
        if a == 2:
            rx = min(x, W)
        if a == 3:
            by = y
        if a == 4:
            ty = min(y, H)

    print(max(0, (rx-lx)*(ty-by)))


main()

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(a1,a2,a3,a4)
if (int(a2)-int(a1)) > 0 and (int(a4)-int(a3)) > 0:
    print((int(a2)-int(a1))*(int(a4)-int(a3)))
else:
    print(0)