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: Accepted

Solution code:


#２２０5~

import sys
[a,b,c]=list(map(int,input().split()))# W H N
lst=[]
for i in range(c):
    lst.append(list(map(int,input().split())))
#print(a,b,c,lst)

lstxmax=[0]
lstxmin=[a]
lstymax=[0]
lstymin=[b]
for i in lst:
    if i[2]==1:
        lstxmax.append(i[0])
    if i[2]==2:
        lstxmin.append(i[0])
    if i[2]==3:
        lstymax.append(i[1])
    if i[2]==4:
        lstymin.append(i[1])

xmin=min(lstxmin)
xmax=max(lstxmax)
ymin=min(lstymin)
ymax=max(lstymax)

#print(xmax,xmin,ymax,ymin)
if xmin-xmax>=0 and ymin-ymax>=0:
    print((xmin-xmax)*(ymin-ymax))
else:
    print(0)

Submission status: Accepted

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

xmin = 0
ymin = 0
xmax = W
ymax = H
for x,y,a in XYA:
  if a == 1:
    xmin = max(x,xmin)
  elif a == 2:
    xmax = min(x,xmax)
  elif a == 3:
    ymin = max(y,ymin)
  else:
    ymax = min(y,ymax)
#print(xmax,xmin,ymax,ymin)
print(max(xmax-xmin,0)*max(ymax-ymin,0))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
p = [map(int, input().split()) for _ in range(N)]
w_left = 0
w_right = W
h_bottom = 0
h_top = H

for x, y, a in p:
    if a == 1:
        w_left = max(w_left, x)
    elif a == 2:
        w_right = min(w_right, x)
    elif a == 3:
        h_bottom = max(h_bottom, y)
    else:
        h_top = min(h_top, y)

ans = max(0, w_right - w_left) * max(0, h_top - h_bottom)

print(ans)

Submission status: Accepted

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

g = [[1 for _ in range(w)] for __ in range(h)]

for _ in range(n):
    x, y, a = map(int, input().split())
    for i in range(h):
        for j in range(w):
            if a == 1 and j < x:
                g[i][j] = 0
            elif a == 2 and x <= j:
                g[i][j] = 0
            elif a == 3 and i < y:
                g[i][j] = 0
            elif a == 4 and y <= i:
                g[i][j] = 0

print(sum(map(sum, g)))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
w0 = 0
h0 = 0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        w0 = max(w0,x)
    if a == 2:
        w = min(w,x)
    if a == 3:
        h0 = max(h0,y)
    if a == 4:
        h = min(h,y)
if (w-w0 > 0) and (h-h0 >0):
    print((w-w0)*(h-h0))
else:
    print(0)

Submission status: Accepted

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

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

    if a == 1:
        w0 = max(w0,x)
    
    if a == 2:
        w  = min(w,x)

    if a == 3:
        h0 = max(h0,y)
    
    if a == 4:
        h  = min(h,y)

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

Submission status: Accepted

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

W_right = W
W_left = 0
H_up = H
H_down = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if W_left < x:
            W_left = x
    elif a == 2:
        if W_right > x:
            W_right = x
    elif a == 3:
        if H_down < y:
            H_down = y
    else:
        if H_up > y:
            H_up = y

if W_right >= W_left and H_up >= H_down:
    print((W_right - W_left) * (H_up - H_down))
else:
    print(0)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x=int(0)
y=int(0)
sx=int(w)
sy=int(h)
for i in range(n):
    X,Y,a=map(int,input().split())
    if a==1:
        if x<X:
            x=X
    elif a==2:
        if X<sx:
            sx=X
    elif a==3:
        if y<Y:
            y=Y
    else:
        if Y<sy:
            sy=Y

if sx<x or sy<y:
    print(0)

else:
    print((sx-x)*(sy-y))

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

w,h,n=LI()
x,X=0,w
y,Y=0,h
for i in ' '*n:
    s,t,a=LI()
    if a==1:
        x=max(x,s)
    elif a==2:
        X=min(X,s)
    elif a==3:
        y=max(y,t)
    elif a==4:
        Y=min(Y,t)

print(max(0,X-x)*max(0,Y-y))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
white_mostleft=0
white_mostright=w
white_mostup=h
white_mostdown=0

for _ in range(n):
    x,y,a=map(int,input().split())
    if(a==1 and white_mostleft < x):
        white_mostleft=x
    elif(a==2 and white_mostright > x):
        white_mostright=x
    elif(a==3 and white_mostup > h-y):
        white_mostup = h-y
    elif(a==4 and white_mostdown < h-y):
        white_mostdown = h-y

ans=max(0,white_mostright-white_mostleft) * max(0,white_mostup-white_mostdown)
print(ans)

Submission status: Accepted

Solution code:
arr = input().split()
arr = list(map(int, arr))
w = arr[0]
h = arr[1]
n = arr[2]

x = []
y = []
a = []
for i in range(n):
    arr = input().split()
    arr = list(map(int, arr))
    x.append(arr[0])
    y.append(arr[1])
    a.append(arr[2])

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

for i in range(n):
    if a[i] == 1:
        if x1 <= x[i]:
            x1 = x[i]
    elif a[i] == 2:
        if x2 >= x[i]:
            x2 = x[i]
    elif a[i] == 3:
        if y2 <= y[i]:
            y2 = y[i]
    elif a[i] == 4:
        if y1 >= y[i]:
            y1 = y[i]           

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

Submission status: Accepted

Solution code:
import numpy as np
w, h, n = map(int, input().split())

mat = np.ones(w * h).reshape(h, w)
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        mat[:, :x] = 0
    elif a == 2:
        mat[:, x:] = 0
    elif a == 3:
        mat[-y+h:, :] = 0
    else:
        mat[:-y+h, :] = 0
print(len(mat[mat == 1]))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
p,q,r,s=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p=max(p,x)
  elif a==2:
    q=min(q,x)
  elif a==3:
    r=max(r,y)
  elif a==4:
    s=min(s,y)
print(max(0,q-p)*max(0,s-r))

Submission status: Accepted

Solution code:
import sys

# W H N X軸の最大、Y軸の最大、点の個数
w, h, n = map(int, input().split())

# xi, yi, ai 点のX座標、Y座標、処理
list = []
for i in range(n):
    xi, yi, ai = map(int, input().split())
    list.append([xi, yi, ai])

# 白で残っている座標初期化
x_min, y_min = 0, 0
x_max, y_max = w, h

for list_1 in list:
    # 処理が 1 なら X軸最小より大きければ入れ替える
    if list_1[2] == 1:
        if x_min < list_1[0]:
            x_min = list_1[0]
    # 処理が 2 なら X軸最大より小さければ入れ替える
    if list_1[2] == 2:
        if x_max > list_1[0]:
            x_max = list_1[0]
    # 処理が 3 なら Y軸最小より大きければ入れ替える
    if list_1[2] == 3:
        if y_min < list_1[1]:
            y_min = list_1[1]
    # 処理が 2 なら X軸最大より小さければ入れ替える
    if list_1[2] == 4:
        if y_max > list_1[1]:
            y_max = list_1[1]

# 残った面積は (X最大 - X最小) * (Y最大 - Y最小)
area = (x_max - x_min) * (y_max - y_min)
if (x_max - x_min) > 0 and (y_max - y_min) > 0:
    print(area)
else:
    print(0)

Submission status: Accepted

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

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

w1 = 0
w2 = w
h1 = 0
h2 = h

for i in range(n):
    if(mat[i][2] == 1 and w1 < mat[i][0]):
        w1 = mat[i][0]
    elif(mat[i][2] == 2 and w2 > mat[i][0]):
        w2 = mat[i][0]
    elif(mat[i][2] == 3 and h1 < mat[i][1]):
        h1 = mat[i][1]
    elif(mat[i][2] == 4 and h2 > mat[i][1]):
        h2 = mat[i][1]
        
print((w2-w1)*(h2-h1) if w2 >= w1 and h2 >= h1 else 0)

Submission status: Accepted

Solution code:
def solve(w, h, n, XYA):
    m = [0, w, 0, h]
    for x, y, a in XYA:
        if a == 1 and m[0] < x:
            m[0] = x
        if a == 2 and m[1] > x:
            m[1] = x
        if a == 3 and m[2] < y:
            m[2] = y
        if a == 4 and m[3] > y:
            m[3] = y
        if m[0] >= m[1] or m[2] >= m[3]:
            return 0
    return (m[1] - m[0]) * (m[3] - m[2])

_w, _h, _n = list(map(int, input().split()))
_XYA = [map(int, input().split()) for _ in range(_n)]
print(solve(_w, _h, _n, _XYA))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	w, h, n = map(int, input().split())
	
	dots = []

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

	x_min = 0
	x_max = w
	y_min = 0
	y_max = h

	for i in range(0,n):
		if dots[i][2] == 1 and x_min < dots[i][0]:
			x_min = dots[i][0]
		elif dots[i][2] == 2 and x_max > dots[i][0]:
			x_max = dots[i][0]
		elif dots[i][2] == 3 and y_min < dots[i][1]:
			y_min = dots[i][1]
		elif dots[i][2] == 4 and y_max > dots[i][1]:
			y_max = dots[i][1]

	if x_min >= x_max or y_min >= y_max:
		ans = 0
	else:
		ans = (x_max - x_min) * (y_max - y_min)

	print(ans)

Submission status: Accepted

Solution code:
def main():
    w,h,n=map(int,input().split())
    L=[tuple(map(int,input().split())) for _ in range(n)]
    xl,xr,yl,yu=0,w,0,h
    for l in L:
        if l[2]<2:
            xl = max(xl,l[0])
        elif l[2]<3:
            xr = min(xr,l[0])
        elif l[2]<4:
            yl = max(yl,l[1])
        else:
            yu = min(yu,l[1])
    # print(max((xr-xl)*(yu-yl),0)) は共に負の時にだめ.
    print(max(xr-xl,0)*max(yu-yl,0))
main()

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)] 
w1=0
h1=0
w2=w
h2=h

for i in a:
    if i[2]==1:
        w1=max(w1,i[0])
    elif i[2]==2:
        w2=min(w2,i[0])
    elif i[2]==3:
        h1=max(h1,i[1])
    elif i[2]==4:
        h2=min(h2,i[1])
if min((w2-w1),(h2-h1))<=0:
    print(0)
else:
    print((w2-w1)*(h2-h1))

Submission status: Accepted

Solution code:
#python3
INF = 10**9

def main():
    w, h, n = map(int, input().split())
    x_max = -1
    x_min = INF
    y_max = -1
    y_min = INF
    for i in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            x_max = max(x_max, x)
        if a == 2:
            x_min = min(x_min, x)     
        if a == 3:
            y_max = max(y_max, y)
        if a == 4:
            y_min = min(y_min, y)

    if x_max == -1:
        x_max = 0 
    if x_min == INF:
        x_min = w
    if y_max == -1:
        y_max = 0
    if y_min == INF:
        y_min = h

    dx_max = x_max
    dx_min = w - x_min
    dy_max = y_max
    dy_min = h - y_min 

    x = w - (dx_max+dx_min)
    y = h - (dy_max+dy_min)

    if (x<=0) | (y<=0):
        print(0)
    else:
        print(x*y)
    
main()

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
x_max = w
x_min = 0
y_max = h
y_min = 0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        x_min = max(x_min,x)
    elif a == 2:
        x_max = min(x_max,x)
    elif a == 3:
        y_min = max(y_min,y)
    elif a == 4:
        y_max = min(y_max,y)
    #print(x_max,x_min,y_max,y_min)
a= max(x_max-x_min,0) 
b =max(y_max-y_min,0)
print(a*b)

Submission status: Accepted

Solution code:
xyas = []

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

x = [0, w]
y = [0, h]
  
for xya in xyas:
  if xya[2] == 1:
    if x[0] < xya[0]:
      x[0] = xya[0]
  elif xya[2] == 2:
    if x[1] > xya[0]:
      x[1] = xya[0]
  elif xya[2] == 3:
    if y[0] < xya[1]:
      y[0] = xya[1]
  else:
    if y[1] > xya[1]:
      y[1] = xya[1]

width = (x[1] - x[0]) 
height = (y[1] - y[0])
if width <= 0 or height <= 0:
  print(0)
else:
  print(width * height)

Submission status: Accepted

Solution code:
a = input().split()
w = int(a[0])
h = int(a[1])
n = int(a[2])

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    a = input().split()
    wp = int(a[0])
    hp = int(a[1])
    ap = int(a[2])
    if ap == 1:
        if x_min < wp:
            x_min = wp
    elif ap == 2:
        if x_max > wp:
            x_max = wp
    elif ap == 3:
        if y_min < hp:
            y_min = hp
    elif ap == 4:
        if y_max > hp:
            y_max = hp
    # print(x_min, x_max, y_min, y_max)

if x_max < x_min:
    ws = 0
else:
    ws = x_max - x_min

if y_max < y_min:
    hs = 0
else:
    hs = y_max - y_min

squea = ws * hs

print(squea)

Submission status: Accepted

Solution code:
#abc047-b
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#x,y,a
x_min=0
y_min=0

for i in l:
    if i[-1]==1:
        x_min=max(i[0],x_min)

    elif i[-1]==2:
        w=min(i[0],w)

    elif i[-1]==3:
        y_min=max(i[1],y_min)

    else:
        h=min(i[1],h)

print((w-x_min)*(h-y_min) if (w-x_min)>0 and (h-y_min)>0 else 0)

Submission status: Accepted

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

L = 0
R = w
D = 0
U = h

for _ in range(n):
    x,y,a = map(int, input().split())
    if a==1:
        L = max(L,x)
    if a==2:
        R = min(R,x)
    if a==3:
        D = max(D,y)
    if a==4:
        U = min(U,y)
    #print(L, R, D, U)

x = max(0, R-L)
y = max(0, U-D)
#print(x, y)
ans = x*y

print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
paint_dot = {}
for _ in range(N):
  t1, t2, t3 = map(int,input().split())
  paint_dot[(t1, t2)] = t3

pattern_H = [1]*H
pattern_W = [1]*W

for key in paint_dot:
  if paint_dot[key] == 1:
    for i in range(key[0]):
      pattern_W[i] = 0
  elif paint_dot[key] == 2:
    for i in range(key[0],W):
      pattern_W[i] = 0
  elif paint_dot[key] == 3:
    for i in range(key[1]):
      pattern_H[i] = 0
  else:
    for i in range(key[1],H):
      pattern_H[i] = 0

print(sum(pattern_W) * sum(pattern_H))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
paint_dot = {}
for _ in range(N):
  t1, t2, t3 = map(int,input().split())
  paint_dot[(t1, t2)] = t3

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

for key in paint_dot:
  x = paint_dot[key]
  if x == 1:
    for row in mat:
      for i in range(key[0]):
        row[i] = 0    
  elif x == 2:    
    for row in mat:
      for i in range(key[0], W):
        row[i] = 0
  elif x == 3:
    for i in range(key[1]):
      for j in range(W):
      	mat[i][j] = 0
  else:
    for i in range(key[1], H):
      for j in range(W):
      	mat[i][j] = 0

#print(mat)
print(sum(map(sum,mat)))

Submission status: Accepted

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

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

for i in range(N):
    if A[i][2] == 1:
        if x1 < A[i][0]:
            x1 = A[i][0]
    elif A[i][2] == 2:
        if x2 > A[i][0]:
            x2 = A[i][0]
    elif A[i][2] == 3:
        if y1 < A[i][1]:
            y1 = A[i][1]
    elif A[i][2] == 4:
        if y2 > A[i][1]:
            y2 = A[i][1]

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

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    w,h,n=INTM()
    X,Y,A=[],[],[]
    for i in range(n):
        x,y,a=INTM()
        X.append(x)
        Y.append(y)
        A.append(a)
    wh=[[0]*w]*h
    for i in range(n):
        if A[i]==1:
            for j in range(h):
                wh[j][0:X[i]]=[1]*X[i]
        elif A[i]==2:
            for j in range(h):
                wh[j][X[i]:w]=[1]*(w-X[i])
        elif A[i]==3:
            wh[0:Y[i]]=[[1]*w]*Y[i]
        else:
            wh[Y[i]:h]=[[1]*w]*(h-Y[i])
        #print(wh)
    ct=0
    
    for i in range(h):
        ct+=sum(wh[i])
    print(h*w-ct)
if __name__ == '__main__':
    do()

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
graph = [[1] * W for _ in range(H)]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(H):
            for j in range(x):
                graph[i][j] = 0
    if a == 2:
        for i in range(H):
            for j in range(x, W):
                graph[i][j] = 0
    if a == 3:
        for i in range(y):
            for j in range(W):
                graph[i][j] = 0
    if a == 4:
        for i in range(y, H):
            for j in range(W):
                graph[i][j] = 0
ans = sum([sum(line) for line in graph])
print(ans)

Submission status: Accepted

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

x=[]
y=[]
a=[]

for j in range(n):
    x.append(data[j][0])
    y.append(data[j][1])
    a.append(data[j][2])

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

for j in range(n):
    if a[j]==1 and x[j]>x1:
        x1=x[j]
    elif a[j]==2 and x[j]<x2:
        x2=x[j]
    elif a[j]==3 and y[j]>y1:
        y1=y[j]
    elif a[j]==4 and y[j]<y2:
        y2=y[j]

if x1>x2 or y1>y2:
    print(0)

else:
    print((x2-x1)*(y2-y1))

Submission status: Accepted

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

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x0=max(x0,x)
  elif a==2:
    w=min(w,x)
  elif a==3:
    y0=max(y0,y)
  elif a==4:
    h=min(h,y)
    
print(max(w-x0,0)*max(h-y0,0))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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=max(x1,x)
    if a==2:
        x2=min(x2,x)
    if a==3:
        y1=max(y1,y)
    if a==4:
        y2=min(y2,y)
print(max((x2-x1)*(y2-y1),0) if x2-x1>0 else 0)

Submission status: Accepted

Solution code:
import numpy as np

W, H, N = map(int, input().split())
area = np.ones((H, W))


def calc_paint(x, y, a):
 #   x -= 1
 #   y -= 1
    if a == 1:
        area[:, :x] = 0
    elif a == 2:
        area[:, x:] = 0
    elif a == 3:
        area[:y, :] = 0
    elif a == 4:
        area[y:, :] = 0


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

print(int(np.sum(area)))

Submission status: Accepted

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

x = []
y = []
a = []

area  = [[True for _ in range(W)] for _ in range(H)]

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

w1 = 0
h1 = 0
w2 = W
h2 = H

for i in range(N):
    if a[i] == 1:
        w1 = max(w1, x[i])
    if a[i] == 2:
        w2 = min(w2, x[i])
    if a[i] == 3:
        h1 = max(h1, y[i])
    if a[i] == 4:
        h2 = min(h2, y[i])

# 負になった場合は0にする
if w2 - w1  < 0 or h2 - h1 < 0:
    S = 0
else:
    S = (w2-w1)*(h2-h1)

print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
X = []
Y = []
A = []
for i in range(N):
    x, y, a = map(int, input().split())
    X.append(x)
    Y.append(y)
    A.append(a)

## 長方形のマスを塗りつぶしていって残ったマス目を数えるイメージ
# 0: 白, 1: 黒
square = []
for i in range(H):
    horizonatlArea = []
    for j in range(W):
        horizonatlArea.append(0)
    square.append(horizonatlArea)

# Aの要素の番号に応じてsquareに1を埋めていく
for n in range(N):
    if A[n] == 1:
        for i in range(X[n]):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 2:
        for i in range(X[n], W):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 3:
        for i in range(W):
            for j in range(Y[n]):
                square[j][i] = 1
    elif A[n] == 4:
        for i in range(W):
            for j in range(Y[n], H):
                square[j][i] = 1

# square内の要素の数を数えて出力
cnt = 0
for j in range(H):
    cnt += square[j].count(0)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

w,h,n = map(int, input().split())
x = ["" for _ in range(n)]
y = ["" for _ in range(n)]
a = ["" for _ in range(n)]

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

hl = 0
hh = 0
wl = 0
wh = 0
for i in range(n):
    if a[i] == 1:
        wl = max(wl, x[i])
    if a[i] == 2:
        wh = max(wh, w - x[i])
    if a[i] == 3:
        hl = max(hl, y[i])
    if a[i] == 4:
        hh = max(hh, h - y[i])

"""
print("wl :", wl)
print("wh :", wh)
print("hl :", hl)
print("hh :", hh)
"""

ans_w = w - (wl+wh)
ans_h = h - (hl+hh)

if ans_w < 0 or ans_h < 0:
    print(0)
else:
    print(ans_w*ans_h)

Submission status: Accepted

Solution code:
wmax,hmax,n = map(int,input().split())
wmin = hmin = 0
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    if wmin < x:
      wmin = x
  elif a == 2:
    if wmax > x:
      wmax = x
  elif a == 3:
    if hmin < y:
      hmin = y
  else:
    if hmax > y:
      hmax = y

if wmax-wmin < 0 or hmax-hmin < 0:
  print(0)
else:
  print((wmax-wmin) * (hmax-hmin))

Submission status: Accepted

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)
  elif a==2:
    maxX = min(maxX,x)
  elif a==3:
    minY = max(minY,y)
  elif a==4:
    maxY = min(maxY,y)

#print(minX,maxX,minY,maxY)
    
if minX >= maxX or minY >= maxY:
  print(0)
else:
  print((maxX - minX)*(maxY - minY))

Submission status: Accepted

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)
    elif a==2:
        maxx=min(maxx,x)
    elif a==3:
        miny=max(miny,y)
    elif a==4:
        maxy=min(maxy,y)
print(max((maxx-minx),0)*max(0,(maxy-miny)))

Submission status: Accepted

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

x_min = max((xya[0] for xya in XYA if xya[2] == 1), default=0)
x_max = min((xya[0] for xya in XYA if xya[2] == 2), default=W)
y_min = max((xya[1] for xya in XYA if xya[2] == 3), default=0)
y_max = min((xya[1] for xya in XYA if xya[2] == 4), default=H)
print(max(x_max - x_min, 0) * max(y_max - y_min, 0))

Submission status: Accepted

Solution code:
W,H,N = map(int, input().split())
start = [0,0]
end = [W,H]

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

print(max(0, end[0]-start[0])*max(0, end[1]-start[1]))

Submission status: Accepted

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

x_min = max([0] + [xya[0] for xya in XYA if xya[2] == 1])
x_max = min([W] + [xya[0] for xya in XYA if xya[2] == 2])
y_min = max([0] + [xya[1] for xya in XYA if xya[2] == 3])
y_max = min([H] + [xya[1] for xya in XYA if xya[2] == 4])
print(max(x_max - x_min, 0) * max(y_max - y_min, 0))

Submission status: Accepted

Solution code:
def solve():
    W,H,N = map(int, input().split())
    xl,xr = 0,W
    yl,yr = 0,H
    for _ in range(N):
        x,y,a = map(int, input().split())
        if a == 1:
            xl = max(xl, x)
        elif a == 2:
            xr = min(xr, x)
        elif a == 3:
            yl = max(yl, y)
        elif a == 4:
            yr = min(yr, y)
    
    print((xr-xl)*(yr-yl) if xr-xl > 0 and yr-yl > 0 else 0)
    
solve()

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
min_X, max_X = 0, w
min_Y, max_Y = 0, 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)
    elif a == 4:
        max_Y = min(y, max_Y)

W = max(0, max_X - min_X)
H = max(0, max_Y - min_Y)
print(W*H)

Submission status: Accepted

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

x_min = 0
y_min = 0
x_max = w
y_max = h

for i in range(n):
    if p[i][2] == 1:
        x_min = max(x_min, p[i][0])
    elif p[i][2] == 2:
        x_max = min(x_max, p[i][0])
    elif p[i][2] == 3:
        y_min = max(y_min, p[i][1])
    else:
        y_max = min(y_max, p[i][1])

w_l = x_max - x_min
h_l = y_max - y_min

if w_l > 0 and h_l > 0:
    print(w_l * h_l)
else:
    print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
minx, maxx = 0, W
miny, maxy = 0, H

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

width = max(0, maxx-minx)
height = max(0, maxy-miny)

print(width*height)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
sx, sy, ex, ey = 0, 0, W, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = max([x, sx])
    elif a == 2:
        ex = min([x, ex])
    elif a == 3:
        sy = max([y, sy])
    else:
        ey = min([y, ey])

w, h = ex-sx, ey-sy
if w < 0 or h < 0:
    print(0)
else:
    print((ex-sx)*(ey-sy))

Submission status: Accepted

Solution code:
def main():
    W, H, N = (int(i) for i in input().split())
    seen = [[True]*W for h in range(H)]

    for i in range(N):
        x, y, a = (int(i) for i in input().split())
        if a == 1:
            for h in range(H):
                for w in range(x):
                    seen[h][w] = False
        elif a == 2:
            for h in range(H):
                for w in range(x, W):
                    seen[h][w] = False
        elif a == 3:
            for h in range(y):
                for w in range(W):
                    seen[h][w] = False
        elif a == 4:
            for h in range(y, H):
                for w in range(W):
                    seen[h][w] = False

    ans = 0
    for i in range(H):
        for j in range(W):
            if seen[i][j]:
                ans += 1
    print(ans)
    # print(*seen, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

x_one_max = 0
x_two_min = w
y_three_max = 0
y_four_min = h

for i in range(n):
    if XYA[i][2] == 1:
        x_one_max = max(XYA[i][0], x_one_max)
    elif XYA[i][2] == 2:
        x_two_min = min(XYA[i][0], x_two_min)
    elif XYA[i][2] == 3:
        y_three_max = max(XYA[i][1], y_three_max)
    elif XYA[i][2] == 4:
        y_four_min = min(XYA[i][1], y_four_min)

x_dif = x_two_min - x_one_max
y_dif = y_four_min - y_three_max
if x_dif <= 0 or y_dif <= 0:
    ans = 0
else:
    ans = x_dif * y_dif
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

w, h, n = map(int, input().split())
grid = np.array([[0] * w for _ in range(h)])
# print(grid)


def F(grid, x, y, a):
    if a == 1:
        grid[:, :x] = 1
    elif a == 2:
        grid[:, x:] = 1
    elif a == 3:
        grid[:y, :] = 1
    elif a == 4:
        grid[y:, :] = 1


for i in range(n):
    x, y, a = map(int, input().split())
    F(grid, x, y, a)
    # print(grid)
print(np.count_nonzero(grid == 0))