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:
a,b,c=map(int,input().split())
x1=0
x2=a
y1=0
y2=b
for i in range(c):
    e,f,g=map(int,input().split())
    if g==1:
        if x1<e:
            x1=e
    elif g==2:
        if x2>e:
            x2=e
    elif g==3:
        if y1<f:
            y1=f
    else:
        if y2>f:
            y2=f
if 0>(x2-x1)*(y2-y1):
    print(0)
else:
    print((x2-x1)*(y2-y1))

Submission status: Wrong Answer

Solution code:
a,b,c=map(int,input().split())
x1=0
x2=a
y1=0
y2=b
for i in range(c):
    e,f,g=map(int,input().split())
    if g==1:
        x1=e
    elif g==2:
        x2=e
    elif g==3:
        y1=f
    else:
        y2=f
if 0>(x2-x1)*(y2-y1):
    print(0)
else:
    print((x2-x1)*(y2-y1))

Submission status: Wrong Answer

Solution code:
a,b,c=map(int,input().split())
x1=0
x2=a
y1=0
y2=b
for i in range(c):
    e,f,g=map(int,input().split())
    if g==1:
        x1=e
    elif g==2:
        x2=e
    elif g==3:
        y1=f
    else:
        y2=f
print((x2-x1)*(y2-y1))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
lis = []
xi = 0
yi = 0
xj = 0
yj = 0
for i in range(N):
    #lis.append(list(map(int, input().split())))
    x, y, a = map(int, input().split())
    if a==1:
        xi += x
    elif a==2:
        xj += x
    elif a==3:
        yi += y
    elif a==4:
        yj += y

x = (W-xj)-xi

if x<0:
    x = 0
y = (H-yj)-yi
if y<0:
    y = 0

print(x*y)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
x1, x2, y1, y2 = 0, W, 0, H

for _ 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
    else:
        y2 = y

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

Submission status: Wrong Answer

Solution code:
import sys

W, H, N = map(int, sys.stdin.readline().strip().split())
opes = []
for _ in range(N):
    x, y, a = map(int, sys.stdin.readline().strip().split())
    opes.append((x, y, a))

x_min = 0
x_max = W
y_min = 0
y_max = H
for (x, y, a) in opes:
    if a == 1:
        x_min = max(x_min, x)
    elif a == 2:
        x_max = min(x_max, x)
    if a == 3:
        y_min = max(y_min, y)
    if a == 4:
        y_max = min(y_max, y)

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

Submission status: Wrong Answer

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

    corners = [0, 0, w, h]

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

        if a == 1:
            corners[0] = x
        elif a == 2:
            corners[2] = x
        elif a == 3:
            corners[1] = y
        else:
            corners[3] = y
    
    width = corners[2] - corners[0]
    height = corners[3] - corners[1]

    if width < 0 or height < 0:
        print(0)
    else:
        print(width * height)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    corners = [0, 0, w, h]

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

        if a == 1:
            corners[0] = x
        elif a == 2:
            corners[2] = x
        elif a == 3:
            corners[1] = y
        else:
            corners[3] = y
    
    res = (corners[2] - corners[0]) * (corners[3] - corners[1])

    if res < 0:
        print(0)
    else:
        print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

p1 = (0, 0)
p2 = (w, h)

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

area = (p2[0]-p1[0])*(p2[1]-p1[1])

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

Submission status: Wrong Answer

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

p1 = (0, 0)
p2 = (w, h)

for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        p1 = (x, p1[1])
    elif a == 2:
        p2 = (x, p2[1])
    elif a == 3:
        p1 = (p1[0], y)
    elif a == 4:
        p2 = (p2[0], y)

area = (p2[0]-p1[0])*(p2[1]-p1[1])

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
l=[list(map(int,input().split())) for i in range(N)]
l_s,b_s = 0,0
r_s,u_s = W,H
for i in range(N):
    if l[i][2]==1 and l_s < l[i][0]:
        l_s =l[i][0]
    elif l[i][2]==2 and r_s > l[i][0]:
        r_s = l[i][0]
    elif l[i][2]==3 and b_s < l[i][1]:
        b_s = l[i][1]
    elif l[i][2]==4 and u_s > l[i][1]:
        u_s = l[i][1]
#print(r_s,l_s,u_s,b_s)
print((r_s-l_s)*(u_s-b_s))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
area=[0,w,0,h] # weight start,stop height start, stop
for i in range(n):
    if li[i][2]==1:
        area[0]=li[i][0]
    elif li[i][2]==2:
        area[1]=li[i][0]
    elif li[i][2]==3:
        area[2]=li[i][1]
    elif li[i][2]==4:
        area[3]=li[i][1]

weight=area[1]-area[0]
height=area[3]-area[2]
if weight<=0 or height<=0:
  ans=0
else:
  ans=weight*height

print(ans)

Submission status: Wrong Answer

Solution code:
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))


a,b,c  = cin()
p = -1
q = 1e9
r = -1
s = 1e9
for i in range(c):
  x,y,z = cin()
  if z==1:
    p = max(x,p)
  elif z==2:
    q = min(x,q)
  elif z==3:
    r = max(r,y)
  else:
    s = min(s,y)

if p==-1:
    p = 0
if q==1e9:
    q = a
if r==-1:
    r=0
if s==1e9:
    s=b

ans = (q-p)*(s-r)
if p>q or r>q:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))


a,b,c  = cin()
p = -1
q = 1e9
r = -1
s = 1e9
for i in range(c):
  x,y,z = cin()
  if z==1:
    p = max(x,p)
  elif z==2:
    q = min(x,q)
  elif z==3:
    r = max(r,y)
  else:
    s = min(s,y)

if p==-1:
    p = 0
if q==1e9:
    q = a
if r==-1:
    r=0
if s==1e9:
    s=b

# v = a-(a-p-1+a-q)
# w = b-(b-r+b-s)
# print(v,w)
ans = (q-p)*(s-r)
if ans>0:
    print(ans)
else:
    print(0)
# print(ans if ans>0 else 0)

# l1 = list(range(0,p+1))
# l2 = list(range(q,a))
# l1 = set(l1)
# l2 = set(l2)
# l3 = l1.union(l2)

# l4 = list(range(0,r))
# l5 = list(range(s,b+1))
# l4 = set(l4)
# l5 = set(l5)
# l6 = l4.union(l5)
# # print(l3,l6)
# # print(l1,l2)
# # print(p,q,r,s)
# if(len(l3)==a or len(l6)==b):
#     print(0)
# else:
#     print((a-len(l3)+1)*(b-len(l6)+1))

Submission status: Wrong Answer

Solution code:
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))


a,b,c  = cin()
p = -1
q = 1e9
r = -1
s = 1e9
for i in range(c):
  x,y,z = cin()
  if z==1:
    p = max(x,p)
  elif z==2:
    q = min(x,q)
  elif z==3:
    r = max(r,y)
  else:
    s = min(s,y)

if p==-1:
    p = 0
if q==1e9:
    q = a
if r==-1:
    r=0
if s==1e9:
    s=b

# v = a-(a-p-1+a-q)
# w = b-(b-r+b-s)
# print(v,w)

l1 = list(range(0,p+1))
l2 = list(range(q,a))
l1 = set(l1)
l2 = set(l2)
l3 = l1.union(l2)

l4 = list(range(0,r))
l5 = list(range(s,b+1))
l4 = set(l4)
l5 = set(l5)
l6 = l4.union(l5)
# print(l3,l6)
# print(l1,l2)
# print(p,q,r,s)
if(len(l3)==a or len(l6)==b):
    print(0)
else:
    print((a-len(l3)+1)*(b-len(l6)+1))

Submission status: Wrong Answer

Solution code:
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))


a,b,c  = cin()
p = -1
q = 1e9
r = -1
s = 1e9
for i in range(c):
  x,y,z = cin()
  if z==1:
    p = max(x,p)
  elif z==2:
    q = min(x,q)
  elif z==3:
    r = max(r,y)
  else:
    s = min(s,y)

if p==-1:
    p = 0
if q==1e9:
    q = a
if r==-1:
    r=0
if s==1e9:
    s=b

# v = a-(a-p-1+a-q)
# w = b-(b-r+b-s)
# print(v,w)

l1 = list(range(0,p+1))
l2 = list(range(q,a))
l1 = set(l1)
l2 = set(l2)
l3 = l1.union(l2)

l4 = list(range(0,r))
l5 = list(range(s,b+1))
l4 = set(l4)
l5 = set(l5)
l6 = l4.union(l5)
print(l3,l6)
# print(l1,l2)
print(p,q,r,s)
if(len(l3)==a or len(l6)==b):
    print(0)
else:
    print((a-len(l3)+1)*(b-len(l6)+1))

Submission status: Wrong Answer

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

X = Y = 0

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

    if a == 1:
        X = max(X, x)
    if a == 2:
        w = min(w, x)
    if a == 3:
        Y = max(Y, y)
    else:
        h = min(h, y)

print(max(w-X, 0)*max(h-Y, 0))

Submission status: Wrong Answer

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

X = Y = 0

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

    if a == 1:
        X = max(X, x)
    if a == 2:
        W = min(w, x)
    if a == 3:
        Y = max(Y, y)
    else:
        h = min(h, y)

print(max(w-X, 0)*max(h-Y, 0))

Submission status: Wrong Answer

Solution code:

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

x1 = 0
x2 = w
y1 = 0
y2 = h

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        x1 = x
    elif a == 2:
        x2 = x
    elif a == 3:
        y1 = y
    elif a == 4:
        y2 = y

if x1 >= x2 or y1 >= y2:
    print(0)
else:
    print(abs(x1-x2)*abs(y1-y2))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
X=Y=0
for _ in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
      X = max(X, x)
    elif a == 2:
      W = min(W, x)
    elif a == 3:
      Y = max(Y, y)
    elif a == 4:
      H = min(H, y)
    ans = (W - X) * (H - Y)
if ans < 0:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
X=Y=0
for _ in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
      X = max(X, x)
    elif a == 2:
      W = min(W, x)
    elif a == 3:
      Y = max(Y, y)
    elif a == 4:
      H = min(H, y)
    ans = (W - X) * (H - Y)
    if ans < 0:
      ans = 0
        
print(ans)

Submission status: Wrong Answer

Solution code:
def myAnswer(W:int,H:int,N:int,X:list,Y:list,A:list) -> int:
   startX = 0
   endX = W
   startY = 0
   endY = H
   for x,y,a in zip(X,Y,A):
      if(a == 1):
         startX = x
      elif(a == 2):
         endX = x
      elif(a == 3):
         startY = y
      else:
         endY = y
   # print(startX,endX,startY,endY)
   return 0 if(startX > endX or startY > endY) else (endX - startX) * (endY - startY)

def modelAnswer():
   return
def main():
   W,H,N = map(int,input().split())
   X = []
   Y = []
   A = []
   for _ in range(N):
      x,y,a = map(int,input().split())
      X.append(x)
      Y.append(y)
      A.append(a)
   print(myAnswer(W,H,N,X,Y,A))
if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
X=Y=0
for _ in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
      X = max(X, x)
    elif a == 2:
      W = min(W, x)
    elif a == 3:
      Y = max(Y, y)
    elif a == 4:
      H = min(H, y)
    ans = (W - X) * (H - Y)        
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7


w,h,n = map(int,input().split())
whiteXmin = 0
whiteXmax = w
whiteYmin = 0
whiteYmax = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        whiteXmin = max(x,whiteXmin)
    if a == 2:
        whiteXmax = min(x,whiteXmax)
    if a == 3:
        whiteYmin= max(y,whiteYmin)
    if a == 4:
        whiteYmax = min(y,whiteYmax)
s = (whiteXmax-whiteXmin)*(whiteYmax-whiteYmin)
print(max(s,0))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7


w,h,n = map(int,input().split())
whiteXmin = 0
whiteXmax = w
whiteYmin = 0
whiteYmax = h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        whiteXmin = max(x,whiteXmin)
    elif a == 2:
        whiteXmax = min(x,whiteXmax)
    elif a == 3:
        whiteYmin= max(y,whiteYmin)
    else:
        whiteYmax = min(y,whiteYmax)
s = (whiteXmax-whiteXmin)*(whiteYmax-whiteYmin)
print(max(s,0))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    W, H, N = map(int, readline().split())
    xl = 0
    xr = W
    yl = 0
    yh = H
    for _ in range(N):
        x, y, a = map(int, readline().split())
        if a==1:
            xl = max(xl,x)
        elif a==2:
            xr = min(xr,x)
        elif a==3:
            yl = max(yl,y)
        else:
            yh = min(yh,y)
    print(max(xl-xr,0)*max(yh-yl,0))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
from itertools import combinations
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    W, H, N = map(int, readline().split())
    xl = 0
    xr = W
    yl = 0
    yh = H
    for _ in range(N):
        x, y, a = map(int, readline().split())
        if a==1:
            xl = max(xl,x)
        elif a==2:
            xr = min(xr,x)
        elif a==3:
            yl = max(yl,y)
        else:
            yh = min(yh,y)
    print(max(0,(xr-xl)*(yh-yl)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    W, H, N = [int(item) for item in input().split()]
    query = [[int(item) for item in input().split()] for _ in range(N)]

    x_high = -3
    x_low = W+3
    y_high = -3
    y_low = H+3

    for x, y, a in query:
        if a == 1:
            x_low = min(x_low, x)
        elif a == 2:
            x_high = max(x_high, x)
        elif a == 3:
            y_low = min(y_low, y)
        else:
            y_high = max(y_high, y)

        # print(x,y,a)
        # print(x_low, x_high, y_low, y_high)
        # print('-----------')
    
    if x_low == W+3:
        x_low = 0
    if x_high == -3:
        x_high = W
    if y_low == H+3:
        y_low = 0
    if y_high == -3:
        y_high = H

    # print('##############')
    # print(x,y,a)
    # print(x_low, x_high, y_low, y_high)
    # print('-----------')

    x_delta = x_high - x_low
    y_delta = y_high - y_low

    if x_delta >= 0 and y_delta >= 0:
        print(x_delta*y_delta)
    else:
        print(0)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    W, H, N = [int(item) for item in input().split()]
    query = [[int(item) for item in input().split()] for _ in range(N)]

    x_high = 0
    x_low = W
    y_high = 0
    y_low = H

    for x, y, a in query:
        if a == 1:
            x_low = min(x_low, x)
        elif a == 2:
            x_high = max(x_high, x)
        elif a == 3:
            y_low = min(y_low, y)
        else:
            y_high = max(y_high, y)

        # print(x,y,a)
        # print(x_low, x_high, y_low, y_high)
        # print('-----------')
    
    if x_low == W:
        x_low = 0
    if x_high == 0:
        x_high = W
    if y_low == H:
        y_low = 0
    if y_high == 0:
        y_high = H

    # print('##############')
    # print(x,y,a)
    # print(x_low, x_high, y_low, y_high)
    # print('-----------')

    x_delta = x_high - x_low
    y_delta = y_high - y_low

    if x_delta >= 0 and y_delta >= 0:
        print(x_delta*y_delta)
    else:
        print(0)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
W,H,N=3,3,1
x0,y0=0,0
for i in range(N):
    x,y,a=3,1,1
    if a==1 and x>x0:
        x0=x
    elif a==2 and x<W:
        W=x
    elif a==3 and y>y0:
        y0=y
    elif a==4 and y<H:
        H=y
if W<x0 or H<y0:
    print(0)
else:
    print((W-x0)*(H-y0))

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
x0,y0=0,0
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1 and x>x0:
        x0=x
    elif a==2 and x<W:
        W=x
    elif a==3 and y>y0:
        y0=y
    elif a==4 and y<H:
        H=y
print((W-x0)*(H-y0))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
x = []
y = []
a = []
for i in range(n):
    xx,yy,aa = map(int,input().split())
    x.append(xx)
    y.append(yy)
    a.append(aa)

l = 0
r = w
t = h
b = 0


for i, aa in enumerate(a):
    if aa == 1:
        l = max(l,x[i])
    elif aa == 2:
        r = min(r,x[i])

    elif aa == 3:
        b = max(b,y[i])
    elif aa == 4:
        t = min(t,y[i])

ans = max(0,(r-l) * (t-b))
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

w, h, n = map(int,input().split())
now = [[1]*w]*h
li = [list(map(int,input().split())) for i in range(n)]

for x in li:
    if x[2]==1: #x以下を塗りつぶす
        for i in range(h):
            now[i] = [0]*x[0] + [1]*(w-x[0])
    if x[2]==2: #x以上を塗りつぶす
        for i in range(h):
            now[i] = [1]*(w-x[0]) + [0]*x[0]
    if x[2]==3: #y以下を塗りつぶす
        for i in range(x[1]):
            now[i] = [0]*w
    if x[2]==4: #y以上を塗りつぶす
        for i in range(x[1],h):
            now[i] = [0]*w

for i in now:
        print(i)
print(sum(list(itertools.chain.from_iterable(now))))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

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

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    w, h, n = map(int, input().split())
    lx, uy, rx, ty = 0, 0, w, h
    for i in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            lx = max(lx, x)
        elif a == 2:
            rx = min(rx, x)
        elif a == 3:
            uy = max(uy, y)
        else:
            ty = min(ty, y)
    print(max(0, (rx - lx) * (ty - uy)))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
a,b,c,d=0,w,0,h
for x,y,A in l:
    if A==1:
        a=max(a,x)
    elif A==2:
        b=min(b,x)
    elif A==3:
        c=max(c,y)
    else:
        d=min(d,y)
# print(f"b-a:{b-a},d-c:{d-c}")
print((b-a)*(d-c))

Submission status: Wrong Answer

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

bottom_left = [0, 0]
top_right = [W, H]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        bottom_left[0] = max(bottom_left[0], x)
    elif a == 2:
        top_right[0] = min(top_right[0], x)
    elif a == 3:
        bottom_left[1] = max(bottom_left[1], y)
    elif a == 4:
        top_right[1] = min(top_right[1], y)

w = top_right[0] - bottom_left[0]
h = top_right[1] - bottom_left[1]
print(max(0, w*h))

Submission status: Wrong Answer

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

one = 0
two = W
three = 0
four = H
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        one = max(one, x)
    elif a == 2:
        two = min(two, x)
    elif a == 3:
        three = max(three, y)
    elif a == 4:
        four = min(four, y)

w = W - (one + (W - two))
h = H - (three + (H - four))
print(max(0, w*h))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
ll=[list(map(int,input().split()))for i in range(N)]
wmax=W
hmax=H
wmin=0
hmin=0
for i in range(N):
    if ll[i][2]==1 and ll[i][0]>=wmin:
        wmin=ll[i][0]
    elif ll[i][2]==2 and ll[i][0]<=wmax:
        wmax=ll[i][0]
    elif ll[i][2]==3 and ll[i][1]>=hmin:
        hmin=ll[i][1]
    elif ll[i][2]==4 and ll[i][1]<=hmax:
        hmax=ll[i][1]
ans = (wmax-wmin)*(hmax-hmin)
if ans >=0:
    print((wmax-wmin)*(hmax-hmin))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
W,H,N=map(int,input().split())
ll=[list(map(int,input().split()))for i in range(N)]
wmax=W
hmax=H
wmin=0
hmin=0
for i in range(N):
    if ll[i][2]==1:
        wmin=ll[i][0]
    elif ll[i][2]==2:
        wmax=ll[i][0]
    elif ll[i][2]==3:
        hmin=ll[i][1]
    else:
        hmax=ll[i][1]
ans = (wmax-wmin)*(hmax-hmin)
if ans >=0:
    print((wmax-wmin)*(hmax-hmin))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def resolve():
    W, H, N = list(map(int, input().split()))
    XYA = [list(map(int, input().split())) for i in range(N)]
    xmin, xmax, ymin, ymax = 0, W, 0, H
    for xya in XYA:
        if xya[2] == 1:
            xmin = max(xmin, xya[0])
        elif xya[2] == 2:
            xmax = min(xmax, xya[0])
        elif xya[2] == 3:
            ymin = max(ymin, xya[1])
        elif xya[2] == 4:
            ymax = min(ymax, xya[1])
    print(max((xmax-xmin)*(ymax-ymin), 0))

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
xya = [list(map(int,input().split())) for _ in range(n)]
X1,Y1 = 0,0
X2,Y2 = w,h
for x,y,a in xya:
    if a == 1 and X1 < x: X1 = x
    elif a == 2 and (X2 == w or X2 < x < w): X2 = x
    elif a == 3 and Y1 < y: Y1 = y
    elif a == 4 and (Y2 == h or Y2 < y < h): Y2 = y
print((X2-X1) * (Y2-Y1) if (X2-X1) * (Y2-Y1) > 0 else 0)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
left = 0
right = w
under = 0
hight= h

for i in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        left = x
    elif a==2:
        right = x
    elif a==3:
        under = y
    else:
        hight = y

if left>=right or under>=hight:
    print(0)
else:
    print((right-left)*(hight-under))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
xya = [list(map(int,input().split())) for _ in range(n)]
X1,Y1 = 0,0
X2,Y2 = w,h
for x,y,a in xya:
    if a == 1 and X1 < x: X1 = x
    elif a == 2 and X2 > x: X2 = x
    elif a == 3 and Y1 < y: Y1 = y
    elif a == 4 and Y2 > y: Y2 = y
print((X2-X1) * (Y2-Y1) if (X2-X1) * (Y2-Y1) > 0 else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    W,H,N=pin()
    ans=[0,W,0,H]#ans[[xの範囲][yの範囲]]
    for n in range(N):
        x,y,a=pin()
        if a==1:
            ans[0]=max(ans[0],x)
        elif a==2:
            ans[1]=min(ans[1],x)
        elif a==3:
            ans[2]=max(ans[2],y)
        else:
            ans[3]=min(ans[3],y)
    t=((ans[1]-ans[0])*(ans[3]-ans[2]))
    if t<0:t=0
    print(t)    
#%%submit!
resolve()