Problem:


Score : 200 points

Problem Statement

There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.

Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).

Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

If a_i = 1, he painted the region satisfying x < x_i within the rectangle.

If a_i = 2, he painted the region satisfying x > x_i within the rectangle.

If a_i = 3, he painted the region satisfying y < y_i within the rectangle.

If a_i = 4, he painted the region satisfying y > y_i within the rectangle.

Find the area of the white region within the rectangle after he finished painting.

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

0 ≦ x_i ≦ W (1 ≦ i ≦ N)

0 ≦ y_i ≦ H (1 ≦ i ≦ N)

W, H (21:32, added), x_i and y_i are integers.

a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

Input

The input is given from Standard Input in the following format:

W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

Now, the area of the white region within the rectangle is 9.

Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64



Sample input:
5 4 2
2 1 1
3 3 4


Sample output:
9

Submission status: Wrong Answer

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

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:
    if x_min < x:
      x_min = x
  elif a == 2:
    if x_max > x:
      x_max = x
  elif a == 3:
    if y_min < y:
      y_min = y
  elif a == 4:
    if y_max > y:
      y_max = y
S = (x_max-x_min)*(y_max-y_min)
if S < 0:
  print(0)
else:
  print(S)

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
  elif a == 4:
    y_max = y
S = (x_max-x_min)*(y_max-y_min)
if S < 0:
  print(0)
else:
  print(S)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
W = [0, w]
H = [0, h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and W[0] < x:
        W[0] = x
    elif a == 2 and W[1] > x:
        W[1] = x
    elif a == 3 and H[0] < y:
        H[0] = y
    elif a == 4 and H[1] > y:
        H[1] = y

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

Submission status: Wrong Answer

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

l, r, b, u = 0, w, 0, h
for x, y, a in xya:
    if a == 1:
        l = max(x,l)
    elif a == 2:
        r = min(x,r)
    elif a == 3:
        b = max(y,b)
    elif a == 4:
        u = min(y,u)
print(max(0,(r - l) * (u - b)))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
a = 0
b = 0
for i in range(n):
    if ls[i][2] == 1:
        if ls[i][0] > a:
            a = ls[i][0]
    elif ls[i][2] == 2:
        if ls[i][0] < w:
            w = ls[i][0]
    elif ls[i][2] == 3:
        if ls[i][0] > b:
            b = ls[i][1]
    else:
        if ls[i][0] < h:
            h = ls[i][1]
if (a < w) and (b < h):
    print((w-a)*(h-b))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
w,h,n = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
a = 0
b = 0
for i in range(n):
    if ls[i][2] == 1:
        if ls[i][0] > a:
            a = ls[i][0]
    elif ls[i][2] == 2:
        if ls[i][0] < w:
            w = ls[i][0]
    elif ls[i][2] == 3:
        if ls[i][0] > b:
            b = ls[i][1]
    else:
        if ls[i][0] < h:
            h = ls[i][1]
    if (a >= w) or (b >= h):
        print(0)
        sys.exit()
if (a < w) and (b < h):
    print((w-a)*(h-b))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
w,h,n = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
a = 0
b = 0
for i in range(n):
    if ls[i][2] == 1:
        a = ls[i][0]
    elif ls[i][2] == 2:
        w = ls[i][0]
    elif ls[i][2] == 3:
        b = ls[i][1]
    else:
        h = ls[i][1]
    if (a >= w) or (b >= h):
        print(0)
        sys.exit()
if (a < w) and (b < h):
    print((w-a)*(h-b))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
sx, sy, gx, gy = 0, 0, W, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = max(sx, x)
    elif a == 2:
        gx = min(gx, x)
    elif a == 3:
        sy = max(sy, y)
    else:
        gy = min(gy, y)

S = (gx - sx) * (gy - sy)
if S < 0:
    S = 0
print(S)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
minx = 0
maxx = w
miny = 0
maxy = h

for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    minx = max(minx,x)
  if a == 2:
    maxx = min(maxx,x)
  if a == 3:
    miny = max(miny,y)
  if a == 4:
    maxy = min(maxy,y)

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

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
xya = [list(map(int,input().split())) for i in range(n)]
minx = 0
maxx = w
miny = 0
maxy = h

for i in range(n):
  if xya[i][2] == 1:
    minx = xya[i][0]
  if xya[i][2] == 2:
    maxx = xya[i][0]
  if xya[i][2] == 3:
    miny = xya[i][1]
  if xya[i][2] == 4:
    maxy = xya[i][1]
      
if minx >= maxx or miny >= maxy:
  print(0)
else:
  print((maxx-minx)*(maxy-miny))

Submission status: Wrong Answer

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

for i in range(n):
  if xya[i][2] == 1:
    wl[0] = xya[i][0]
    if wl[1] - wl[0] <= 0:
      print(0)
      exit()
  if xya[i][2] == 2:
    wl[1] = xya[i][0]
    if wl[1] - wl[0] <= 0:
      print(0)
      exit()
  if xya[i][2] == 3:
    hl[0] = xya[i][1]
    if hl[1] - hl[0] <= 0:
      print(0)
      exit()
  if xya[i][2] == 4:
    hl[1] = xya[i][1]
    if hl[1] - hl[0] <= 0:
      print(0)
      exit()
      
print((wl[1]-wl[0])*(hl[1]-hl[0]))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
sikaku_x = [0, w]
sikaku_y = [0, h]
for x, y, a in xya:
    if a == 1:
        if sikaku_x[0] < x:
            sikaku_x[0] = x
    elif a == 2:
        if sikaku_x[1] > x:
            sikaku_x[1] = x
    elif a == 3:
        if sikaku_y[0] < y:
            sikaku_y[0] = y
    elif a == 4:
        if sikaku_y[1] > y:
            sikaku_y[1] = y

white_x = sikaku_x[1] - sikaku_x[0]
white_y = sikaku_y[1] - sikaku_y[0]

ans = white_x*white_y
if ans <= 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
sikaku_x = [0, w]
sikaku_y = [0, h]
for x, y, a in xya:
    if a == 1:
        if sikaku_x[0] <= x:
            sikaku_x[0] = x
    elif a == 2:
        if sikaku_x[1] >= x:
            sikaku_x[1] = x
    elif a == 3:
        if sikaku_y[0] <= y:
            sikaku_y[0] = y
    else:
        if sikaku_y[1] >= y:
            sikaku_y[1] = y

white_x = sikaku_x[1] - sikaku_x[0]
white_y = sikaku_y[1] - sikaku_y[0]

ans = white_x*white_y
if ans <= 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
sikaku_x = [0, w]
sikaku_y = [0, h]
for x, y, a in xya:
    if a == 1:
        if sikaku_x[0] < x:
            sikaku_x[0] = x
    elif a == 2:
        if sikaku_x[1] > x:
            sikaku_x[1] = x
    elif a == 3:
        if sikaku_y[0] < y:
            sikaku_y[0] = y
    else:
        if sikaku_y[1] > y:
            sikaku_y[1] = y

white_x = sikaku_x[1] - sikaku_x[0]
white_y = sikaku_y[1] - sikaku_y[0]

ans = white_x*white_y
if ans < 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,N=map(int,input().split())
X,Y,W,H=0,0,w,h
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:X=x
    elif a==2:W=x
    elif a==3:Y=y
    else:H=y
    if X>=w or Y>=h or W<=0 or H<=0:
        print(0)
        exit()
print((W-X)*(H-Y) if X<=W and Y<=H else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
temphu=h
temphd=0
tempwu=w
tempwd=0
temp=w*h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    temp=max(0,temp-max(0,temphu-temphd)*max(x-tempwd,0))
    tempwd=x
  if a==2:
    temp=max(0,temp-max(0,temphu-temphd)*max(tempwu-x,0))
    tempwu=x
  if a==3:
    temp=max(0,temp-max(0,tempwu-tempwd)*max(y-temphd,0))
    temphd=y
  if a==4:
    temp=max(0,temp-max(0,tempwu-tempwd)*max(temphu-y,0))
    temphu=y
print(temp)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
temphu=h
temphd=0
tempwu=w
tempwd=0
temp=w*h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    temp=max(0,temp-max(0,(temphu-temphd))*(max(x-tempwd,0)))
    tempwd=x
  if a==2:
    temp=max(0,temp-max(0,(temphu-temphd))*(max(tempwu-x,0)))
    tempwu=x
  if a==3:
    temp=max(0,temp-max(0,(tempwu-tempwd))*(max(y-temphd,0)))
    temphd=y
  if a==4:
    temp=max(0,temp-max(0,(tempwu-tempwd))*(max(temphu-y,0)))
    temphu=y
print(temp)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
temphu=h
temphd=0
tempwu=w
tempwd=0
temp=w*h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    temp=max(0,temp-(temphu-temphd)*(max(x-tempwd,0)))
    tempwd=x
  if a==2:
    temp=max(0,temp-(temphu-temphd)*(max(tempwu-x,0)))
    tempwu=x
  if a==3:
    temp=max(0,temp-(tempwu-tempwd)*(max(y-temphd,0)))
    temphd=y
  if a==4:
    temp=max(0,temp-(tempwu-tempwd)*(max(temphu-y,0)))
    temphu=y
print(int(temp))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
temphu=h
temphd=0
tempwu=w
tempwd=0
temp=w*h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    temp=max(0,temp-(temphu-temphd)*(max(x-tempwd,0)))
    tempwd=x
  if a==2:
    temp=max(0,temp-(temphu-temphd)*(max(tempwu-x,0)))
    tempwu=x
  if a==3:
    temp=max(0,temp-(tempwu-tempwd)*(max(y-temphd,0)))
    temphd=y
  if a==4:
    temp=max(0,temp-(tempwu-tempwd)*(max(temphu-y,0)))
    temphu=y
print(temp)

Submission status: Wrong Answer

Solution code:
w, h, n = [int(i) for i in input().split()]
x_list = []
y_list = []
a_list = []
left = 0
right = w
upper = h
lower = 0

for i in range(n):
	x, y, a = [int(k) for k in input().split()]
	if a == 1:
		left = x
	elif a == 2:
		right = x
	elif a == 3:
		lower = y
	elif a == 4:
		upper = y

S = (right-left)*(upper-lower)
if right-left < 0 or upper-lower < 0:
	print(0)
else:
	print(S)

Submission status: Wrong Answer

Solution code:
w, h, n = [int(i) for i in input().split()]
x_list = []
y_list = []
a_list = []
left = 0
right = w
upper = h
lower = 0

for i in range(n):
	x, y, a = [int(k) for k in input().split()]
	if a == 1:
		left = x
	elif a == 2:
		right = x
	elif a == 3:
		lower = y
	elif a == 4:
		upper = y

S = (right-left)*(upper-lower)
if S < 0:
	print(0)
else:
	print(S)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

W, H, N = MAP()

dict = defaultdict(int)
dict[1] = 0
dict[2] = W
dict[3] = 0
dict[4] = H

for _ in range(N):
	x, y, a = MAP()
	if a == 1:
		dict[1] = max(x, dict[1])
	elif a == 2:
		dict[2] = min(x, dict[2])
	elif a == 3:
		dict[3] = max(y, dict[3])
	elif a == 4:
		dict[4] = min(y, dict[4])

#print(dict)
print(max(0, (dict[2]-dict[1])*(dict[4]-dict[3])))

Submission status: Wrong Answer

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

high = h
low = 0
left = 0
right = w

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        left = max(left, x)
    elif a == 2:
        right = max(right, x)
    elif a == 3:
        low = max(low, y)
    elif a == 4:
        high = max(high, y)

print(max(high - low, 0)*max(right - left, 0))

Submission status: Wrong Answer

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


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:
        low = max(low, y)
    else:
        high = min(high, y)

print(max((high - low)*(right - left), 0))

Submission status: Wrong Answer

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

left = 0
right = W
bottom = 0
top = 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:
    bottom = max(bottom, y)
  else:
    top = min(top, y)
    
print(max(0, (right-left) * (top-bottom)))

Submission status: Wrong Answer

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

left = 0
right = W
bottom = 0
top = 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:
    bottom = max(bottom, y)
  else:
    top = min(top, y)
    
print((right-left) * (top-bottom))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
x1,y1,x2,y2=0,0,w,h
for i in range(n):
    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
print(max(x2-x1,0)*max(y2-y1,0))

Submission status: Wrong Answer

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

w0 = 0
h0 = 0

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

for i in c:
    if i[2] == 2:
        if i[0] < w:
            w = i[0]
    elif i[2] == 1:
        if i[0] > 0:
            w0 = i[0]
    elif i[2] == 4:
        if i[1] < h:
            h = i[1]
    elif i[2] == 3:
        if i[1] > 0:
            h0 = i[1]

w = w - w0 
if w < 0:
    w = 0
h = h - h0
if h < 0:
    h = 0
print(w*h)

Submission status: Wrong Answer

Solution code:
W,H,N = map(int,input().split())
x_r = W
x_l = 0
y_r = H
y_l = 0

for _ in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        x_l = max(x,x_l)
    elif a == 2:
        x_r = min(x,x_r)
    elif a == 3:
        y_l = max(y,y_l)
    else:
        y_r = min(y,y_r)

print(max(0,(x_r-x_l)*(y_r-y_l)))

Submission status: Wrong Answer

Solution code:
W,H,N = map(int,input().split())
x_r = W
x_l = 0
y_r = H
y_l = 0

for _ in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        x_l = x
    elif a == 2:
        x_r = x
    elif a == 3:
        y_l = y
    else:
        y_r = y

print(max(0,(x_r-x_l)*(y_r-y_l)))

Submission status: Wrong Answer

Solution code:

W,H,N = map(int, input().split())
bottom = [0, 0]
top = [W,H]

for _ in range(N):
    x,y,a = map(int, input().split())
    if a==1:
        bottom[0] = max(bottom[0], x)
    elif a==2:
        top[0] = min(top[0], x)
    elif a==3:
        bottom[1] = max(bottom[1], y)
    elif a==4:
        top[1] = min(top[1], y)

print(max(0, (top[0]-bottom[0])*(top[1]-bottom[1])))

Submission status: Wrong Answer

Solution code:

W,H,N = map(int, input().split())
bottom = [0, 0]
top = [W,H]

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

print(max(0, (top[0]-bottom[0])*(top[1]-bottom[1])))

Submission status: Wrong Answer

Solution code:

W,H,N = map(int, input().split())
bottom = [0, 0]
top = [W,H]

for _ in range(N):
    x,y,a = map(int, input().split())
    if a==1:
        bottom[0] = x
    elif a==2:
        top[0] = x
    elif a==3:
        bottom[1] = y
    else:
        top[1] = y

print(max(0, (top[0]-bottom[0])*(top[1]-bottom[1])))

Submission status: Wrong Answer

Solution code:

W,H,N = map(int, input().split())
bottom = [0, 0]
top = [W,H]

for _ in range(N):
    x,y,a = map(int, input().split())
    if a==1:
        bottom[0] = x
    elif a==2:
        top[0] = x
    elif a==3:
        bottom[1] = y
    else:
        top[1] = y

print(max(0, (top[0]-bottom[0])*(top[1]-bottom[1])))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(n)]
x1, x2 = 0, w
y1, y2 = 0, h
for i in range(n):
    if L[i][2] == 1:
        x1 = L[i][0]
    elif L[i][2] == 2:
        x2 = L[i][0]
    elif L[i][2] == 3:
        y1 = L[i][1]
    elif L[i][2] == 4:
        y2 = L[i][1]
S = max(0, x2 - x1) * max(0, y2 - y1)
print(S)

Submission status: Wrong Answer

Solution code:
def main():
  n = list(map(int,input().split()))
  x_ans=[0,n[0]]
  y_ans=[0,n[1]] 
  x = [0] * n[2]
  y = [0] * n[2]
  t = [0] * n[2]
  for i in range(n[2]):
    x[i], y[i],t[i] = map(int, input().split())
  for i in range(0,n[2]):
    if t[i]==1 and x_ans[0]<x[i]:
      x_ans[0]=x[i]
    elif t[i]==2 and x[i]<x_ans[1]:
      x_ans[1]=x[i]
    elif t[i]==3 and y_ans[0]<y[i]:
      y_ans[0]=y[i]
    elif t[i]==4 and y[i]<y_ans[1]:
      y_ans[1]=y[i]
  if x_ans[0]>x_ans[1] or y_ans[0]>y_ans[1]:
    print(0)
  else:
    print((x_ans[1]-x_ans[0])*y_ans[1]-y_ans[0])
     
main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

W,H,N = IL()

l = [[1]*W for i in range(H)]

for _ in range(N):
  x,y,t = IL()
  if t==1:
    for i in range(H):
      l[i][:x] = [0 for j in range(x)]
  if t==2:
    for i in range(H):
      l[i][-x:] = [0 for j in range(W-x)]
  
  if t==4:
    for i in range(y,H):
      l[i] = [0 for i in range(W)]
  if t==3:
    for i in range(y):
      l[i] = [0 for i in range(W)]

P(sum(sum(l[i]) for i in range(H)))

Submission status: Wrong Answer

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

d = [[0], [W], [0], [H]]

for x, y, a in xya:
    if a == 1 or a == 2:
        d[a-1] += [x]
    else:
        d[a-1] += [y]

ret = (max(d[0]) - min(d[1])) * (max(d[2]) - min(d[3]))
print(max(ret, 0))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n = [int(x) for x in input().split()]
xy = []
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    xy.append(tmp)

r = w
u = h
l = 0
b = 0

for z in xy:
    if z[2] == 1:
        l = max(l, z[0])
    elif z[2] == 2:
        r = min(r, z[0])
    elif z[2] == 3:
        b = max(b, z[1])
    elif z[2] == 4:
        u = min(u, z[1])

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    w, h, n = mi()
    xmin, xmax, ymin, ymax = 0, w, 0, h

    for _ in range(n):
        x, y, a = mi()
        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((ymax-ymin)*(xmax-xmin), 0))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split(" "))
grouped_dots = {1: [], 2: [], 3: [], 4: []}

dots = []
for _ in range(n):
  dots.append(list(map(int, input().split(" "))))

for dot in dots:
  if dot[-1] in (1, 2):
    grouped_dots[dot[-1]].append(dot[0])
  else:
    grouped_dots[dot[-1]].append(dot[1])

x_min = max(grouped_dots[1]) if len(grouped_dots[1]) > 1 else 0
x_max = min(grouped_dots[2]) if len(grouped_dots[2]) > 1 else w
y_min = max(grouped_dots[3]) if len(grouped_dots[3]) > 1 else 0
y_max = min(grouped_dots[4]) if len(grouped_dots[4]) > 1 else  h
x = 0 if x_max - x_min < 0 else x_max - x_min
y = 0 if y_max - y_min < 0 else y_max - y_min
print(x * y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

    if a == 1:
        grid[:, :x] = 0
    elif a == 2:
        grid[:, x:] = 0
    elif a == 3:
        grid[:y, :] = 0
    else:
        grid[y:, :] = 0

print(np.count_nonzero(grid.ravel()))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
x_li = [0]*n
y_li = [0]*n
a_li = [0]*n
for i in range(n):
    x_li[i],y_li[i],a_li[i] = map(int,input().split())

area = [0,0,w,h]#x1,y1,x2,y2
for i in range(n):
    a,x,y = a_li[i],x_li[i],y_li[i]
    if a==1:
        area[0]=x
    if a==2:
        area[2]=x
    if a==3:
        area[1]=y
    if a==4:
        area[3]=y
#print(area)
print(max(0,(area[2]-area[0]))*max(0,(area[3]-area[1])))