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:
W,H,N = map(int,input().split())
board = [[0]*W for i in range(H)]
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        for j in range(H):
            for k in range(x):
                board[j][k]=1
    if a == 2:
        for j in range(H):
            for k in range(x,W):
                board[j][k]=1
    if a == 3:
        for j in range(W):
            for k in range(y):
                board[k][j]=1
    if a == 4:
        for j in range(W):
            for k in range(y,H):
                board[k][j]=1
ans = 0
for i in range(H):
    ans += board[i].count(0)
print(ans)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split(" "))
x = [0]*N
y = [0]*N
a = [0]*N
for i in range(N):
    x[i],y[i],a[i]=map(int,input().split(" "))

i = 0
rx = W
ry = H
lx = 0
ly = 0
while i < N:
    if a[i] == 1:
        lx = max(x[i],lx)
    elif a[i] == 2:
        rx = min(x[i],rx)
    elif a[i] == 3:
        ly = max(y[i],ly)
    elif a[i] == 4:
        ry = min(y[i],ry)
    i += 1

print(max(rx-lx,0)*max(ry-ly,0))

Submission status: Accepted

Solution code:
W,H,N = (int(i) for i in input().split())

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

x_max = max([i[0] if i[2] == 1 else 0 for i in l])
x_min = min([i[0] if i[2] == 2 else W for i in l])
y_max = max([i[1] if i[2] == 3 else 0 for i in l])
y_min = min([i[1] if i[2] == 4 else H for i in l])

x = min(x_max+(W-x_min),W)
y = min(y_max+(H-y_min),H)

print(W*H - x*H - y*W + x*y)

Submission status: Accepted

Solution code:
import numpy as np
w,h,n=map(int,input().split())
l=np.ones((w,h))
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        l[:x,:] = 0
    elif a==2:
        l[x:,:] = 0
    elif a==3:
        l[:,:y] = 0
    else:
        l[:,y:] = 0
print(int(np.sum(l)))

Submission status: Accepted

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

xa = [0]
xb = [W]
ya = [0]
yb = [H]


for i in range(N):
    if a[i][2] == 1:
        xa.append(a[i][0])
    elif a[i][2] == 2:
        xb.append(a[i][0])
    elif a[i][2] == 3:
        ya.append(a[i][1])
    elif a[i][2] == 4:
        yb.append(a[i][1])

x1 = max(xa)
x2 = min(xb)
y1 = max(ya)
y2 = min(yb)
if x1 < x2 and y1 < y2:
    print((x2 - x1) * (y2 - y1))
else:
    print("0")

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
record=[]
xmin=[]
xmax=[]
ymin=[]
ymax=[]

for i in range(n):
    x,y,a=list(map(int,input().split()))
    record.append([x,y,a])
    
for i in range(n):
    if record[i][2] == 1:
        xmin.append(record[i][0])
    elif record[i][2] == 2:
        xmax.append(record[i][0])
    elif record[i][2] == 3:
        ymin.append(record[i][1])
    else:
        ymax.append(record[i][1])

if xmax==[] and xmin==[]:
    X=w
elif xmax==[]:
    X=w-max(xmin)
elif xmin==[]:
    X=min(xmax)-0
else:
    X=min(xmax)-max(xmin)

if ymax==[] and ymin==[]:
    Y=h
elif ymax==[]:
    Y=h-max(ymin)
elif ymin==[]:
    Y=min(ymax)-0
else:
    Y=min(ymax)-max(ymin)
    
print(X*Y) if (X > 0 and Y > 0) else print(0)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
LIX = []
LIY = []
LIA = []
for i in range(N):
    A,B,C = map(int,input().split())
    LIX.append(A)
    LIY.append(B)
    LIA.append(C)
    
NUMX = []
NUMY = []
for i in range(W):
    NUMX += [i+1]
for i in range(H):
    NUMY += [i+1]
    
for i in range(N):
    if LIA[i] == 1:
        for j in range(LIX[i]):
            if j+1 in NUMX:
                NUMX.remove(j+1)
    if LIA[i] == 3:
        for j in range(LIY[i]):
            if j+1 in NUMY:
                NUMY.remove(j+1)
    if LIA[i] == 2:
        for j in range(LIX[i]+1, W+1):
            if j in NUMX:
                NUMX.remove(j)
    if LIA[i] == 4:
        for j in range(LIY[i]+1, H+1):
            if j in NUMY:
                NUMY.remove(j)
print(len(NUMX)*len(NUMY))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

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

if xy[0][0]<xy[0][1] and xy[1][0]<xy[1][1]:
  print((xy[0][1]-xy[0][0])*(xy[1][1]-xy[1][0]))
else:
  print(0)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
X1, X2, Y1, Y2 = 0, W, 0, H

for x, y, a in P:
    if a == 1:
        X1 = max(X1, x)
    elif a == 2:
        X2 = min(X2, x)
    elif a == 3:
        Y1 = max(Y1, y)
    elif a == 4:
        Y2 = min(Y2, y)
else:
    if X2 <= X1 or Y2 <= Y1:
        print(0)
    else:
        print((X2 - X1) * (Y2 - Y1))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
 
x1 = 0 #左端
x2 = W #右端
y3 = 0 #下端
y4 = H #上端
 
# 白い4角形が最小になる上下左右を見つける
for x,y,a in xya:
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y3 = max(y3, y)
    elif a == 4:
        y4 = min(y4, y)
else:
    # 右端が左端より左, 上端が下端より下,だと全部黒
    if x2 <= x1 or y4 <= y3:
        print(0)
    else:
        print((x2-x1) * (y4-y3))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

bw, bh = 0, 0
w, h, n = map(int, input().split())
xya_array = [list(map(int, input().split())) for _ in range(n)]

for i in xya_array:
    if i[2] == 1:
        bw = max(bw, i[0])
    elif i[2] == 2:
        w = min(w, i[0])
    elif i[2] == 3:
        bh = max(bh, i[1])
    elif i[2] == 4:
        h = min(h, i[1])

if w-bw < 0 or h-bh < 0:
    print(0)
else:
    print((w-bw)*(h-bh))

Submission status: Accepted

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

x1 = 0 #左端
x2 = W #右端
y3 = 0 #下端
y4 = H #上端

# 白い4角形が最小になる上下左右を見つける
for x,y,a in xya:
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y3 = max(y3, y)
    elif a == 4:
        y4 = min(y4, y)
else:
    # 右端が左端より左, 上端が下端より下,だと全部黒
    if x2 <= x1 or y4 <= y3:
        print(0)
    else:
        print((x2-x1) * (y4-y3))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
i, j = 0, 0
w, h = W, H
for x, y, a in L:
    if a == 1:
        i = max(i, x)
    if a == 2:
        w = min(w, x)
    if a == 3:
        j = max(j, y)
    if a == 4:
        h = min(h, y)
if w <= i or h <= j:
    print(0)
else:
    print((w - i) * (h - j))

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
minx,maxx,miny,maxy = 0,W,0,H
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        minx = max(x,minx)
    if a == 2:
        maxx = min(x,maxx)
    if a == 3:
        miny = max(y,miny)
    if a == 4:
        maxy = min(y,maxy)
print(max(0, maxx - minx) * max(0, maxy - miny))

Submission status: Accepted

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

def paint(x,y,a):
    if a == 1:
        for i in range(x):
            for j in range(H):
                rectangle[j][i] = 0
    if a == 2:
        for i in range(x,W):
            for j in range(H):
                rectangle[j][i] = 0
    if a == 3:
        for i in range(W):
            for j in range(y):
                rectangle[j][i] = 0
    if a == 4:
        for i in range(W):
            for j in range(y,H):
                rectangle[j][i] = 0


for i in range(N):
    x,y,a = map(int,input().split())
    paint(x,y,a)
ans = 0
for line in rectangle:
    ans += line.count(1)
print(ans)

Submission status: Accepted

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

def solve(W, H, N, X, Y, A):
    dp = [[0]*(W) for i in range(H)]
    count = 0
    
    for i in range(N):
        x_now, y_now, a_now = X[i], Y[i], A[i]
        if(a_now == 1):
            for i in range(H):
                for j in range(x_now):
                    dp[i][j] = 1
        if(a_now == 2):
            for i in range(H):
                for j in range(x_now, W):
                    dp[i][j] = 1
        if(a_now == 3):
            for i in range(y_now):
                for j in range(W):
                    dp[i][j] = 1
        if(a_now == 4):
            for i in range(y_now, H):
                for j in range(W):
                    dp[i][j] = 1
    
    for i in range(H):
        count += dp[i].count(0)
    print(count)
    
if __name__ == '__main__':
    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)
    
    solve(W, H, N, X, Y, A)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xl, xh = (0, W)
yl, yh = (0, H)
for i in range(N):
    x, y, a = map(int, input().split())
    xl = max(xl, x) if (a==1) else xl
    xh = min(xh, x) if (a==2) else xh
    yl = max(yl, y) if (a==3) else yl
    yh = min(yh, y) if (a==4) else yh
print(max(xh-xl, 0)*max(yh-yl, 0))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
z = [list(map(int, input().split())) for _ in range(N)]
one, two, three, four = [0], [W], [0], [H]
for i in range(N):
	if z[i][2] == 1:
		one.append(z[i][0])
	elif z[i][2] == 2:
		two.append(z[i][0])
	elif z[i][2] == 3:
		three.append(z[i][1])
	else:
		four.append(z[i][1])
w = W - max(one) - (W - min(two))
h = H - max(three) - (H - min(four))
if w > 0 and h > 0:
	print(w * h)
else:
	print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Ws = [x for x in range(W + 1)]
Hs = [x for x in range(H + 1)]

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

    if a == 1:
        Ws = list(filter(lambda x: x >= x_i,Ws))
    if a == 2:
        Ws = list(filter(lambda x: x <= x_i,Ws))
    if a == 3:
        Hs = list(filter(lambda y: y >= y_i,Hs))
    if a == 4:
        Hs = list(filter(lambda y: y <= y_i,Hs))

if len(Ws) == 0 or len(Hs) == 0:
    print(0)
else:
    print((Ws[-1] - Ws[0]) * (Hs[-1] - Hs[0]))

Submission status: Accepted

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

for i in range(N):
  if xya[i][2] == 1:
    for a in range(H):
      for b in range(xya[i][0]):
        M[a][b] = 1
  elif xya[i][2] == 2:
    for a in range(H):
      for b in range(W-xya[i][0]):
        M[a][W-b-1] = 1
  elif xya[i][2] == 3:
    for a in range(xya[i][1]):
      for b in range(W):
        M[a][b] = 1
  else:
    for a in range(H-xya[i][1]):
      for b in range(W):
        M[H-a-1][b] = 1
#print(M)
c = 0
for i in range(H):
  c += M[i].count(0)
print(c)

Submission status: Accepted

Solution code:


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

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

    return w, h, n, points


def submit():
    w, h, n, points = read_input()

    area_x = [0, w]
    area_y = [0, h]

    for point in points:
        if point[2] == 1:
            if area_x[0] < point[0]:
                area_x[0] = point[0]
            continue

        if point[2] == 2:
            if point[0] < area_x[1]:
                area_x[1] = point[0]
            continue

        if point[2] == 3:
            if area_y[0] < point[1]:
                area_y[0] = point[1]
            continue

        if point[2] == 4:
            if point[1] < area_y[1]:
                area_y[1] = point[1]
            continue

    if area_x[1] - area_x[0] < 0 or area_y[1] - area_y[0] < 0:
        print(0)
    else:
        print((area_x[1] - area_x[0]) * (area_y[1] - area_y[0]))

if __name__ == '__main__':
    submit()

Submission status: Accepted

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

down = 0
up = H
left = 0
right = W

for i in range(N):
    if a[i] == 1:
        left = max(left, x[i])
    elif a[i] == 2:
        right = min(right, x[i])
    elif a[i] == 3:
        down = max(down, y[i])
    else:
        up = min(up, y[i])

print(max(right-left, 0) * max(up-down, 0))

Submission status: Accepted

Solution code:

def re(x,y,a,rect):
    if a==1:
        for i in range(1,len(rect)):
            rect[i][1:x+1]=[0]*x
    elif a==2:
        for i in range(1,len(rect)):
            rect[i]=rect[i][:x+1]+[0]*(len(rect[i])-x-1)
    elif a==3:
        for i in range(1,y+1):
            rect[i]=[0]*(len(rect[y]))
    else:
        for i in range(y+1,len(rect)):
            rect[i]=[0]*(len(rect[y]))
        
    return rect



w,h,n=map(int,input().split())
rect=[[0]*(w+1)]
for i in range(h):
    rect+=[[0]+[1]*w]

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


cnt=0
for k in range(h+1):
    cnt+=sum(rect[k])
print(cnt)

Submission status: Accepted

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

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(H):
            box[j] = [1] * x + box[j][x:]
    elif a == 2:
        for j in range(H):
            box[j] = box[j][:x] + [1] * (W-x)
    elif a == 3:
        for j in range(y):
            box[j] = [1] * W
    else:
        for j in range(y, H):
            box[j] = [1] * W

Sum = 0
for i in box:
    Sum += sum(i)

print(W*H - Sum)

Submission status: Accepted

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

# 左下の座標
X=Y=0

for i 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)
  else:
    H=min(H,y)

# 出力
print(max(W-X,0)*max(H-Y,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[W,H,N] = list(map(int,input().split()))
minx = 0
maxx = W
miny = 0
maxy = H
for i in range(N):
    [x,y,a] = list(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)
    else:
        maxy = min(maxy,y)
print(max(0,maxx-minx)*max(0,maxy-miny))

Submission status: Accepted

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

Submission status: Accepted

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

ans = [[0, 0], [W, H]]
for x, y, a in XYA:
    if a == 1 and x > ans[0][0]:
        ans[0][0] = x
    elif a == 2 and x < ans[1][0]:
        ans[1][0] = x
    elif a == 3 and y > ans[0][1]:
        ans[0][1] = y
    elif a == 4 and y < ans[1][1]:
        ans[1][1] = y

x_length = ans[1][0] - ans[0][0]
y_length = ans[1][1] - ans[0][1]
if x_length > 0 and y_length >0:
    print(x_length * y_length)
else:
    print(0)

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    W, H, N = map(int, input().split())
    xl = 0
    xr = W
    yu = H
    yd = 0
    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:
            yd = max(yd, y)
        else:
            yu = min(yu, y)

    if xr <= xl or yu <= yd:
        return 0

    return (xr - xl) * (yu - yd)


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
w, h, n = [int(item) for item in input().split()]

boundary = [[0], [w], [0], [h]]
for i in range(n):
    x, y, a = [int(item) for item in input().split()]
    if a == 1 or a == 2:
        val = x
    elif a == 3 or a == 4:
        val = y
    else:
        exit()
    boundary[a-1].append(val)
    
w = min(boundary[1]) - max(boundary[0])
h = min(boundary[3]) - max(boundary[2])
if w >= 0 and h >= 0:
    print(w*h)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
a,b,c=map(int, input().split())
d=[list(map(int,input().split())) for s in range(c)]
e=np.zeros((a,b),dtype=int)
for i in d:
    if i[2]==1:
        for j in range(i[0]):
            for k in range(b):
                e[j][k]=1
    if i[2]==2:
        for j in range(i[0],a):
            for k in range(b):
                e[j][k]=1
    if i[2]==3:
        for j in range(i[1]):
            for k in range(a):
                e[k][j]=1
    if i[2]==4:
        for j in range(i[1],b):
            for k in range(a):
                e[k][j]=1
f=[a]*b-sum(e)
print(sum(f))

Submission status: Accepted

Solution code:
#47
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)
    elif a==2:
        w = min(w,x)
    elif a==3:
        h0 = max(h0,y)
    elif a==4:
        h = min(h,y)
if w-w0<0 or h-h0<0:
    print(0)
else:
    print((w-w0)*(h-h0))

Submission status: Accepted

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

for i in range(N):
    l = input().split()
    x = int(l[0])
    y = int(l[1])
    a = int(l[2])
    if a == 1:
        if x_list[0] < x:
            x_list[0] = x
    if a == 2:
        if x_list[1] > x:
            x_list[1] = x
    if a == 3:
        if y_list[0] < y:
            y_list[0] = y
    if a == 4:
        if y_list[1] > y:
            y_list[1] = y
            
S = (x_list[1] - x_list[0]) * (y_list[1] - y_list[0])

if x_list[1] - x_list[0] <= 0 or y_list[1] - y_list[0] <= 0:
    print(0)
else:
    print(S)

Submission status: Accepted

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

X_max=[0]
X_min=[w]
Y_max=[0]
Y_min=[h]


for i in range(n):
    if X[i][2]==1:
        X_max.append(X[i][0])
    elif X[i][2]==2:
        X_min.append(X[i][0])
    elif X[i][2]==3:
        Y_max.append(X[i][1])
    elif X[i][2]==4:
        Y_min.append(X[i][1])

a=min(X_min)-max(X_max)
b=min(Y_min)-max(Y_max)

if a<=0 or b<=0:
    ans=0
else:
    ans=a*b


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

area = [[0 for i in range(w)] for j in range(h)]

for i in range(n):
    a,b,c = map(int, input().split())
    if(c == 1):
        for j in range(h):
            for k in range(a):
                area[j][k] = 1
    if (c == 2):
        for j in range(h):
            for k in range(a,w):
                area[j][k] = 1
    if(c == 3):
        for j in range(b):
            for k in range(w):
                area[j][k] = 1
    if (c == 4):
        for j in range(b,h):
            for k in range(w):
                area[j][k] = 1

counter = 0

for i in range(h):
    for j in range(w):
        if(area[i][j] == 0):
            counter += 1

print(counter)

Submission status: Accepted

Solution code:
import numpy as np

i = list(map(int, input().split()))
array=np.ones((i[1],i[0]))

n=[]
for l in range(i[2]):
    x,y,z=[int(l) for l in input().split()]
    n.append([x,y,z])

for num in range(i[2]):
  if n[num][2]==1:
    array[:, :n[num][0]]=0
  elif n[num][2]==2:
    array[:, n[num][0]:]=0
  elif n[num][2]==3:
    array[:n[num][1],:]=0
  elif n[num][2]==4:
    array[n[num][1]:,:]=0  
print(array.sum())

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
xM=W
xm=0
yM=H
ym=0
for i in range(N):
    a=list(map(int,input().split()))
    if a[2]==1:
        if a[0]>xm:
            xm=a[0]
        else:
            continue
    elif a[2]==2:
        if a[0]<xM:
            xM=a[0]
        else:
            continue
    elif a[2]==3:
        if a[1]>ym:
            ym=a[1]
        else:
            continue
    else:
        if a[1]<yM:
            yM=a[1]
        else: 
            continue
xl=xM-xm
yl=yM-ym
print(max(0,xl)*max(0,yl))

Submission status: Accepted

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

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        # 黒の領域(x軸)を増やす
        w = max(w, x)
    elif a == 2:
        # 白の領域(x軸)を削る
        W = min(W, x)
    elif a == 3:
        # 黒の領域(y軸)を増やす
        h = max(h, y)
    else:
        # 白の領域(y軸)を削る
        H = min(H, y)

if W < w or H < h:
    print(0)
else:
    print((W-w)*(H-h))

Submission status: Accepted

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

for ls in lists:
    x, y, a = ls[0], ls[1], ls[2]
    if a == 1:
        # xi の左側を塗りつぶす
        for h in range(H):
            for w in range(x):
                cells[h][w] = 1
    elif a == 2:
        # xi の右側を塗りつぶす
        for h in range(H):
            for w in range(x, W):
                cells[h][w] = 1
    elif a == 3:
        # yi の下側を塗りつぶす
        for h in range(H-y, H):
            for w in range(W):
                cells[h][w] = 1
    else:
        # yi の上側を塗りつぶす
        for h in range(H-y):
            for w in range(W):
                cells[h][w] = 1

count = 0
for rows in cells:
    count += rows.count(0)

print(count)

Submission status: Accepted

Solution code:
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(list(map(int,input().split())))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

if h-d>0 and w-l>0:
    print((h-d)*(w-l))
else:
    print(0)

Submission status: Accepted

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

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

for i in range(n):
    a,b,c=map(int,input().split())
    if c==1:
        x=max(x,a)
    elif c==2:
        w=min(w,a)
    elif c==3:
        y=max(y,b)
    elif c==4:
        h=min(h,b)


print(max(0,w-x)*max(0,h-y))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
wlist=[0]*w
hlist=[0]*h
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    for i in range(x):
      wlist[i]=1
  elif a==2:
    for i in range(x,w):
      wlist[i]=1
  elif a==3:
    for i in range(y):
      hlist[i]=1
  elif a==4:
    for i in range(y,h):
      hlist[i]=1
print(wlist.count(0)*hlist.count(0))

Submission status: Accepted

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

h, w = H, W
x0, y0 = 0, 0
ans = 1

for i in range(N):
    if xya[i][2] == 1:
        if xya[i][0] <= w:
            x0 = max(xya[i][0], x0)
        else:
            ans = 0
    elif xya[i][2] == 2:
        if x0 <= xya[i][0] and xya[i][0] <= w:
            w = xya[i][0]
        elif xya[i][0] < x0:
            ans = 0
    elif xya[i][2] == 3:
        if xya[i][1] <= h:
            y0 = max(xya[i][1], y0)
        else:
            ans = 0
    else:
        if y0 <= xya[i][1] and xya[i][1] <= h:
            h = xya[i][1]
        elif xya[i][1] < y0:
            ans = 0
if ans != 0:
    ans = (w - x0) * (h - y0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
W, H, N = map(int,input().split())
Map = np.ones((H, W),dtype = int)
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        Map[:,:x] = 0
    elif a == 2:
        Map[:,x:] = 0
    elif a == 3:
        Map[:y,:] = 0
    else:
        Map[y:,:] = 0
print(Map.sum())

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for i in range(n)]
m=[[0 for i in range(w)]for i in range(h)]
for x,y,a in xya:
    if a==1:
        for i in range(h):
            for j in range(x):
                m[i][j]=1
    elif a==2:
        for i in range(h):
            for j in range(x,w):
                m[i][j]=1
    elif a==3:
        for i in range(y):
            for j in range(w):
                m[i][j]=1
    else:
        for i in range(y,h):
            for j in range(w):
                m[i][j]=1
ans=0
for i in m:
    ans+=i.count(0)
print(ans)

Submission status: Accepted

Solution code:
w,h,n=[int(i) for i in input().split(' ')]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=[int(i) for i in 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)
    
if y2<=y1 or x2 <= x1:
  print(0)
else:
  print(max(0,(y2-y1)*(x2-x1)))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().rstrip().split())
xya = [list(map(int, input().rstrip().split())) for _ in range(N)]
xy = [[0]*H for _ in range(W)]
for i in xya:
    x_y = i[:2]
    a = i[2]
    if a == 1:
        for j in range(x_y[0]):
            xy[j] = list(map(lambda x: x+1, xy[j]))
    elif a == 2:
        for j in range(x_y[0],W):
            xy[j] = list(map(lambda x: x+1, xy[j]))
    elif a == 3:
        y = x_y[1]
        for j in range(W):
            for k in range(H):
                xy[j][k] += 1 if k < y else 0  
    else:
        y = x_y[1]
        for j in range(W):
            for k in range(H):
                xy[j][k] += 1 if k >= y else 0
area = 0
for i in xy:
    area += i.count(0)
print(area)