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())
x,y,a = [0]*n,[0]*n,[0]*n

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

ls = [0,w,0,h]
for i in range(n):
    if a[i]==1:
        ls[0] = max(ls[0],x[i])
    if a[i]==2:
        ls[1] = min(ls[1],x[i]) 
    if a[i]==3:
        ls[2] = max(ls[2],y[i])
    if a[i]==4:
        ls[3] = min(ls[3],y[i])

s  =max((ls[1]-ls[0]),0)*max((ls[3]-ls[2]),0)
print(int(s))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
data=[list(map(int,input().split())) for i in range(N)]
_W=0
_H=0
for i in data:
    if i[2]==1:
        _W=max(i[0],_W)
    if i[2]==2:
        W=min(W,i[0])
    if i[2]==3:
        _H=max(i[1],_H)
    if i[2]==4:
        H=min(H,i[1])

if W-_W<=0 or H-_H<=0:
    print(0)
    exit()
a=int((W-_W)*(H-_H))
if a>0:
    print(a)
else:
    print(0)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 047 B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
import numpy as np

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

for i in range(n):
    xi, yi, a = map(int, input().split())
    if a == 1: #x <= xi
        rectangle[:xi, :] = 1
    elif a == 2: # x >= xi
        rectangle[xi:, :] = 1
    elif a == 3: #y <= yi 
        rectangle[:, :yi] = 1
    else: # y >= yi 
        rectangle[:, yi:] = 1
print(int(w*h - np.sum(rectangle)))

Submission status: Accepted

Solution code:
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
right,up,n= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
#これを消すとなぜかWAになる呪い
left,down = (0,0)
for i in range(n):
    w,h,c =  (int(i) for i in input().split())
    if c == 1:
        left = max(w,left)
    if c == 2:
        right = min(w,right)
    if c == 3:
        down = max(down,h)
    if c == 4:
        up = min(up,h)
l = max(right-left,0)
w = max(up-down,0)
print(l*w)

Submission status: Accepted

Solution code:
w, h, n = map(lambda x: int(x), input().split(' '))
board = [[0] * h for i in range(w)]

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

    start_x = 0
    end_x = w
    start_y = 0
    end_y = h

    if a == 1:
        end_x = x
    if a == 2:
        start_x = x
    if a == 3:
        end_y = y
    if a == 4:
        start_y = y
    
    for j in range(start_x, end_x):
        for k in range(start_y, end_y):
            board[j][k] = 1

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

print(result)

Submission status: Accepted

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

x_min=0
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:
                w=min(w,x)

        elif a==3:
                y_min=max(y_min,y)

        elif a==4:
                h=min(h,y)


white=max(0,(w-x_min))*max(0,(h-y_min))

print(white)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x=[0]*n
y=[0]*n
a=[0]*n
left=0
right=w
up=h
down=0

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

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

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

square = [[0 for i in range(W)] for i in range(H)]


for i in range(N):
    x,y,a = xya[i]
    if a == 1:
        for i in range(H):
            for j in range(x):
                square[i][j] = 1
    elif a == 2:
        for i in range(x,W):
            for j in range(H):
                square[j][i] = 1
    elif a == 3:
        for i in range(W):
            for j in range(y):
                square[j][i] = 1
    elif a == 4:
        for i in range(W):
            for j in range(y,H):
                square[j][i] = 1

black = 0
for i in range(H):
    black += sum(square[i])

print(H*W-black)

Submission status: Accepted

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


x_min=0
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:
        w=min(x,w)

    elif a==3:
        y_min=max(y_min,y)

    elif a==4:
        h=min(y,h)

print(max(0,w-x_min)*max(0,h-y_min))

Submission status: Accepted

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

x_r = [w]
x_l = [0]
y_r = [h]
y_l = [0]
for i in range(n):
    if para[i][2] == 1 : x_l.append(para[i][0])
    elif para[i][2] == 2 :x_r.append(para[i][0])
    elif para[i][2] == 3 : y_l.append(para[i][1])
    else: y_r.append(para[i][1])
x = min(x_r)-max(x_l)
y = min(y_r) - max(y_l)
if x >= 0 and y >= 0 : 
    print("{}".format(x*y))
else: print(0)

Submission status: Accepted

Solution code:
# B問題
W, H , N = map(int, input().split())
xya = []
for i in range(N):
    xya.append(list(map(int, input().split())))
"""
面積を求めるには2点(原点と点(W, H))が分かれば良い
2点の移動を見る
"""
# 初期値
A = [0, 0]   # 原点
C = [W, H]   # 入力された点

# 点A, Cを移動させる関数
def drow(x, y, a):
    if a == 1 and x >= A[0]:
        A[0] = x
    elif a == 2 and x <= C[0]:
        C[0] = x
    elif a == 3 and y >= A[1]:
        A[1] = y
    elif a == 4 and y <= C[1]:
        C[1] = y

flag = True
for i in range(N):   # 入力された各点を移動させる
    drow(xya[i][0], xya[i][1], xya[i][2])
    if A[0] >= C[0] or A[1] >= C[1]:   # 面積が0になる時
        flag = False
        break
if flag:
    print((C[0]-A[0])*(C[1]-A[1]))
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
w1 = 0
h1 = 0
w2 = w
h2 = h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x > w1:
        w1 = x
    elif a == 2 and x < w2:
        w2 = x
    elif a == 3 and h1 < y:
        h1 = y
    elif a == 4 and h2 > y:
        h2 = y

ans = (w2 - w1) * (h2 - h1)
if w2 - w1 < 0 or h2 - h1 < 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
w1 = 0
h1 = 0
w2 = w
h2 = h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x > w1:
        w1 = x
    elif a == 2 and x < w2:
        w2 = x
    elif a == 3 and h1 < y:
        h1 = y
    elif a == 4 and h2 > y:
        h2 = y

ans = (w2 - w1) * (h2 - h1)
if w2 - w1 < 0 or h2 - h1 < 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
field = []
for i in range(0, W):
	lst = []
	for j in range(0, H):
		lst.append(1)
	field.append(lst)
for i in range(0, N):
	x, y, a = map(int, input().split())
	paint = []
	if a == 1: paint = [[0, x], [0, H]]
	elif a == 2: paint = [[x, W], [0, H]]
	elif a == 3: paint = [[0, W], [0, y]]
	elif a == 4: paint = [[0, W], [y, H]]
	for i in range(paint[0][0], paint[0][1]):
		for j in range(paint[1][0], paint[1][1]):
			field[i][j] = 0
cnt = 0
for i in range(0, W):
	for j in range(0, H):
		cnt += field[i][j]
print(cnt)

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
x1=0
x2=W
y1=0
y2=H
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x,x1)
    if a==2:
        x2=min(x,x2)
    if a==3:
        y1=max(y,y1)
    if a==4:
        y2=min(y,y2)
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())

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

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

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    w,h,n = f()

    xmin = 0
    xmax = w

    ymin = 0
    ymax = h
    for i in range(n):
        x,y,a = f()
        if a== 1:
            xmin = max(xmin, x)
        if a == 2:
            xmax = min(xmax, x)
        
        if a== 3:
            ymin = max(ymin, y)
        if a == 4:
            ymax = min(ymax, y)


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


solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x1, x2, y1, y2 = [0], [w], [0], [h]
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y1.append(y)
  else:
    y2.append(y)
print(max(min(x2) - max(x1), 0) * max((min(y2) - max(y1)), 0))

Submission status: Accepted

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

x1, x2, y3, y4 = [0], [w], [0], [h]

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x1.append(x)
    elif a == 2:
        x2.append(x)
    elif a == 3:
        y3.append(y)
    else:
        y4.append(y)

print(max(min(x2) - max(x1), 0) * max(min(y4) - max(y3), 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
W,H,N  =list(map(int,input().split(" ")))
hoko = [0,W,0,H]
l = 0
r = W
ue = H
sita = 0

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

    if a ==1:
      if l < x:
          l = x
    if a == 2:
        if r > x:
            r = x

    if a == 4:
        if ue > y:
            ue = y
    if a == 3:
        if sita < y:
            sita = y

if (r-l) < 0 and (ue-sita) < 0:
    print(0)
else:
    print(max(0,  (r-l) * (ue-sita)   ))

Submission status: Accepted

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

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

print(max(0, W - w) * max(0, H - h))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
ans = W * H
t, b, l, r = H, 0, 0, W
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:
        b = max(b, y)
    else:
        t = min(t, y)
print(max(0, (t - b)) * max(0, (r - l)))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
wz = 0
hz = 0
w_min = 0
h_min = 0
w_max = w
h_max = h
for i in range (n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x >= w_min:
            wz = x
            w_min = x
    if a == 2:
        if x <= w_max:        
            w = x
            w_max = x
    if a == 3:
        if y >= h_min:
            hz = y
            h_min = y
    if a == 4:
        if y <= h_max:
            h = y
            h_max = y
if w_min < w_max and h_min < h_max:
    print((w-wz)*(h-hz))
else:
    print(0)

Submission status: Accepted

Solution code:
w, h, n = list(map(int, input().split()))
xl, xr, yd, yu = 0, w, 0, h
for _ in range(n):
    x, y, a = list(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 and yu > yd:
    print((xr - xl) * (yu - yd))
else:
    print(0)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
x0=0
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)
    else:
        h=min(h,y)
        
if x0>w or y0>h:
    print(0)
else:
    print((w-x0)*(h-y0))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
https://atcoder.jp/contests/abc047/tasks/abc047_b

"""
import sys


def solve(W, H, N, points):
    grid = [[1]*W for _ in range(H)]
    for x, y, a in points:
        if a == 1:
            for cy, row in enumerate(grid):
                for cx in range(x):
                    row[cx] = 0
        elif a == 2:
            for cy, row in enumerate(grid):
                for cx in range(x, W):
                    row[cx] = 0
        elif a == 3:
            for cy in range(y):
                grid[cy] = [0]*W
        elif a == 4:
            for cy in range(y, H):
                grid[cy] = [0]*W

    return sum([sum(row) for row in grid])


def main(args):
    W, H, N = map(int, input().split())
    points = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(W, H, N, points)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
W,H,N = [int(x) for x in input().split()]
xya = [[int(x) for x in input().split()]for _ in range(N)]
rectangle = [[1 for _ in range(W)]for _ in range(H)]
cnt = 0
for i in xya:
    if(i[2]==1):
        for y,li in enumerate(rectangle):
            for x in range(i[0]):
                rectangle[y][x] = 0
    elif(i[2]==2):
        for y,li in enumerate(rectangle):
            for x in range(i[0],W):
                rectangle[y][x] = 0
    elif(i[2]==3):
        for y in range(i[1]):
            rectangle[y] = [0]*W
    else:
        for y in range(i[1],H):
            rectangle[y] = [0]*W
for i in rectangle:
    cnt += sum(i)
print(cnt)

Submission status: Accepted

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

l, r = 0, w
high, low = h, 0

for i 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:
        low = max(low, y)
    if a == 4:
        high = min(high, y)
w = r - l
h = high - low

print(w * h if w > 0 and h > 0 else 0)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
a = [0, w, 0, h]
for i in range(n):
    xi, yi, ai = map(int, input().split())
    if ai == 1:
        a[0] = max(xi, a[0])
    elif ai == 2:
        a[1] = min(xi, a[1])
    elif ai == 3:
        a[2] = max(yi, a[2])
    else:
        a[3] = min(yi, a[3])
print(max(0, a[1] - a[0]) * max(0, a[3] - a[2]))

Submission status: Accepted

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

try:one = sorted(list(filter(lambda x:x[2]==1, xya)), key=lambda x:x[0])[-1][0]
except: one = 0
try: two = sorted(list(filter(lambda x:x[2]==2, xya)), key=lambda x:x[0])[0][0]
except: two = w
try: three = sorted(list(filter(lambda x:x[2]==3, xya)), key=lambda x:x[1])[-1][1]
except: three = 0
try: four = sorted(list(filter(lambda x:x[2]==4, xya)), key=lambda x:x[1])[0][1]
except: four = h

print(max(0,two-one) * max(0,four-three))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    xmin = max(xmin, x)
  if a == 2:
    xmax = min(xmax, x)
  if a == 3:
    ymin = max(ymin, y)
  if a == 4:
    ymax = min(ymax, y)
if xmax <= xmin or ymax <= ymin:
  print(0)
else:
  print((xmax-xmin)*(ymax-ymin))

Submission status: Accepted

Solution code:
# ABC047B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
w, h, n = list(map(int, input().rstrip().split()))
ans = [0, 0, w, h]
for i in range(n):
    x, y, a = list(map(int, input().rstrip().split()))
    if ans[0] < ans[2] and ans[1] < ans[3]:
        if a == 1:
            ans[0] = max(ans[0], x)
        elif a == 2:
            ans[2] = min(ans[2], x)
        elif a == 3:
            ans[1] = max(ans[1], y)
        else:
            ans[3] = min(ans[3], y)
    else:
        print(0)
        break
else:
    res = (ans[2] - ans[0]) * (ans[3] - ans[1])
    print(res if res >= 0 else 0)

Submission status: Accepted

Solution code:
# ABC047B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
w, h, n = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(n)]
ans = [0, 0, w, h]
for i in range(n):
    a = lst[i][2]
    if ans[0] < ans[2] and ans[1] < ans[3]:
        if a == 1:
            ans[0] = max(ans[0], lst[i][0])
        elif a == 2:
            ans[2] = min(ans[2], lst[i][0])
        elif a == 3:
            ans[1] = max(ans[1], lst[i][1])
        else:
            ans[3] = min(ans[3], lst[i][1])
    else:
        print(0)
        break
else:
    res = (ans[2] - ans[0]) * (ans[3] - ans[1])
    print(res if res >= 0 else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xm,xM,ym,yM=0,w,0,h
xya=[[int(i) for i in input().split()] for i in range(n)]
for i in range(n):
    x,y,a=xya[i][0],xya[i][1],xya[i][2]
    if a==1 and xm<x:
        xm=x
    elif a==2 and xM>x:
        xM=x
    elif a==3 and ym<y:
        ym=y
    elif a==4 and yM>y:
        yM=y
if ym>=yM or xm>=xM:
    print(0)
else:
    print((xM-xm)*(yM-ym))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
xya = []
for _ in range(N):
  xya.append( list( map(int, input().split() ) ) )
  
W_0 = H_0 = 0
  
for i in range(N):
  
  if xya[i][2] == 1:
        if W_0 < xya[i][0]:
            W_0 =  xya[i][0]
    
  elif xya[i][2] == 2:
        if W > xya[i][0]:
            W = xya[i][0]
    
  elif xya[i][2] == 3:
        if H_0 < xya[i][1]:
            H_0 = xya[i][1]
    
  elif xya[i][2] == 4:
        if H > xya[i][1]:
            H = xya[i][1]
    
  if (W - W_0 <= 0) or (H - H_0 <= 0):
    break
    
print(max([(W - W_0)*(H - H_0), 0]))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
area = []
for i in range(1, H + 1):
    area.append([1 for n in range(W)])

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for _x in range(0, x):
            for h in range(0, H):
                area[h][_x] = 0
    if a == 2:
        for _x in range(x, W):
            for h in range(0, H):
                area[h][_x] = 0
    if a == 3:
        for _y in range(0, y):
            for w in range(0, W):
                area[_y][w] = 0
    if a == 4:
        for _y in range(y, H):
            for w in range(0, W):
                area[_y][w] = 0
print(sum([item for sublist in area for item in sublist]))

Submission status: Accepted

Solution code:
from collections import deque
W, H, N = map(int, input().split())
X = deque()
Y = deque()
A = deque()
for _ in range(N):
    x, y, a = map(int, input().split())
    X.append(x)
    Y.append(y)
    A.append(a)
a1 = 0
a2 = W
a3 = 0
a4 = H
for i in range(N):
    Ai = A.popleft()
    if Ai == 1:
        a1 = max(a1, X[i])
    elif Ai == 2:
        a2 = min(a2, X[i])
    elif Ai == 3:
        a3 = max(a3, Y[i])
    elif Ai == 4:
        a4 = min(a4, Y[i])
if a1 >= a2 or a3 >= a4:
    print(0)
else:
    print((a2 - a1) * (a4 - a3))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
x=[]
y=[]
a=[]
for i in range(n):
    x1,y1,a1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    a.append(a1)
x_max=w
x_min=0
y_max=h
y_min=0
for i in range(n):
    if a[i]==1:
        x_min = max(x_min,x[i])
    elif a[i]==2:
        x_max = min(x_max,x[i])
    elif a[i]==3:
        y_min = max(y_min,y[i])
    elif a[i]==4:
        y_max = min(y_max,y[i])
ans = (x_max-x_min)*(y_max-y_min)
if x_max < x_min or y_max < y_min:
    print(0)
else:
    print((x_max-x_min)*(y_max-y_min))

Submission status: Accepted

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


for i in range(N):
    if A[i][2]==1:
        for j in range(A[i][0]):
            X[j]=1
    elif A[i][2]==2:
        for j in range(A[i][0],W):
            X[j]=1
    elif A[i][2]==3:
        for j in range(A[i][1]):
            Y[j]=1
    elif A[i][2]==4:
        for j in range(A[i][1],H):
            Y[j]=1
print(X.count(0)*Y.count(0))

Submission status: Accepted

Solution code:
import numpy as np
w,h,n = map(int,input().split())
cl = np.zeros((w, h) , dtype = int)
for i in range(n):
    x, y, a, = map(int,input().split())
    if a ==1: 
        cl[:x, :] = 1
    if a ==2: 
        cl[x:, :] = 1
    if a ==3:
        cl[:, :y] = 1
    if a ==4:
        cl[:, y:] = 1
print(w * h - np.sum(cl))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x_min = 0
x_max = w
y_min = 0
y_max = h

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)
  else:
    y_max = min(y_max, y)
if x_max > x_min and y_max > y_min:
  print((x_max-x_min)*(y_max-y_min))
else:
  print('0')

Submission status: Accepted

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 = max(X, x)
  elif a == 2:
    W = min(W, x)
  elif a == 3:
    Y = max(Y, y)
  elif a == 4:
    H = min(H, y)
    
if (W-X) < 0 or (H-Y) < 0:
  print(0)
else:
  print((W-X)*(H-Y))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

left = max({P[i][0] for i in range(N) if A[i] == 1} | {0})
right = min({P[i][0] for i in range(N) if A[i] == 2} | {W})
bottom = max({P[i][1] for i in range(N) if A[i] == 3} | {0})
top = min({P[i][1] for i in range(N) if A[i] == 4} | {H})
if right <= left or top <= bottom:
    print(0)
else:
    print((right - left) * (top - bottom))

Submission status: Accepted

Solution code:
w, h, n = [int(i) for i in input().split()]
xl = 0
xr = w
yt = h
yb = 0
for ni in range(n):
  x, y, a =[int(i) for i in input().split()]
  if a == 1:
    xl = max(x,xl)
  elif a == 2:
    xr = min(x,xr)
  elif a == 3:
    yb = max(y,yb)
  elif a == 4:
    yt = min(y,yt)
if xl > xr or yb > yt:
  print(0)
else:
  print((xr-xl)*(yt-yb))

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
wz = 0
hz = 0
w_min = 0
h_min = 0
w_max = w
h_max = h
for i in range (n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x >= w_min:
            wz = x
            w_min = x
    if a == 2:
        if x <= w_max:        
            w = x
            w_max = x
    if a == 3:
        if y >= h_min:
            hz = y
            h_min = y
    if a == 4:
        if y <= h_max:
            h = y
            h_max = y
if w_min < w_max and h_min < h_max:
    print((w-wz)*(h-hz))
else:
    print(0)

Submission status: Accepted

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

L1 = []
L2 = []
L3 = []
L4 = []
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        L1.append(x)
    if a == 2:
        L2.append(x)      
    if a == 3:
        L3.append(y)
    if a == 4:
        L4.append(y)
# print(L1, L2, L3, L4)

if L1 != []:
    x_min = max(L1)
else:
    x_min = 0
    
if L2 != []:
    x_max = min(L2)
else:
    x_max = W
    
if L3 != []:
    y_min = max(L3)
else:
    y_min = 0
    
if L4 != []:
    y_max = min(L4)
else:
    y_max = H
# print(x_min, x_max, y_min, y_max)

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

Submission status: Accepted

Solution code:
import copy

w, h, n = [int(n) for n in input().split()]

a1 = [0]
a2 = [w]
a3 = [0]
a4 = [h]

for i in range(n):
    x, y, a = [int(n) for n in input().split()]
    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    elif a == 4:
        a4.append(y)

x1, x2, y3, y4 = max(a1), min(a2), max(a3), min(a4)

if x1 < x2 and y3 < y4:
    s = (x2 - x1) * (y4 - y3)
else:
    s = 0

print(s)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
l=list(list(map(int,input().split()))for _ in range(n))
xl=0
xh=w
yl=0
yh=h
for i in range(n):
    if l[i][2]==1:xl=max(xl,l[i][0])
    if l[i][2]==2:xh=min(xh,l[i][0])
    if l[i][2]==3:yl=max(yl,l[i][1])
    if l[i][2]==4:yh=min(yh,l[i][1])
print(max((xh-xl),0)*max((yh-yl),0))