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())
wmax = w
wmin = 0
hmax = h
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
    elif a == 4:
        if hmax > y:
            hmax = y

ver = hmax - hmin if hmax > hmin else 0
hor = wmax - wmin if wmax > wmin else 0

print(ver*hor)

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 j in range(H):
            for i in range(x):
                ans[j][i] = 0
                
    elif a == 2:
        for j in range(H):
            for i in range(x, W):
                ans[j][i] = 0

    elif a == 3:
        for j in range(y):
            for i in range(W):
                ans[j][i] = 0        
        
    elif a == 4:
        for j in range(y, H):
            for i in range(W):
                ans[j][i] = 0

print(sum(map(sum, ans)))

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
g = [[0]*w for i in range(h)]
for i in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        for p in range(x):
            for q in range(h):
                g[q][p] = 1
    elif a==2:
        for p in range(x,w):
            for q in range(h):
                g[q][p] = 1
    elif a==3:
        for p in range(w):
            for q in range(y):
                g[q][p] = 1
    else:
        for p in range(w):
            for q in range(y,h):
                g[q][p] = 1
cnt = 0
for i in range(h):
    cnt += g[i].count(0)
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np


def main():
    W, H, N = map(int, input().split())
    s = np.zeros((W, H))
    for _ in range(N):
        x, y, a = map(int, input().split())

        if a == 1:
            s[:x, :] = 1
        elif a == 2:
            s[x:, :] = 1
        elif a == 3:
            s[:, :y] = 1
        elif a == 4:
            s[:, y:] = 1

    print(W * H - np.sum(s))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    w = next_int()
    h = next_int()
    n = next_int()

    x = 0
    y = 0

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

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


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    w = next_int()
    h = next_int()
    n = next_int()
    arr = [[1] * w for _ in range(h)]

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

        for y in range(h):
            for x in range(w):
                if a == 1:
                    if x < xi:
                        arr[y][x] = 0
                if a == 2:
                    if x >= xi:
                        arr[y][x] = 0
                if a == 3:
                    if y < yi:
                        arr[y][x] = 0
                if a == 4:
                    if y >= yi:
                        arr[y][x] = 0

    ans = 0
    for y in range(h):
        ans += sum(arr[y])
    print(ans)


def next_int():
    return int(next_str())


def next_str():
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
from sys import stdin


def main():
    w = next_int()
    h = next_int()
    n = next_int()
    arr = np.ones((h, w), dtype=np.int)

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

        for y in range(h):
            for x in range(w):
                if a == 1:
                    if x < xi:
                        arr[y][x] = 0
                if a == 2:
                    if x >= xi:
                        arr[y][x] = 0
                if a == 3:
                    if y < yi:
                        arr[y][x] = 0
                if a == 4:
                    if y >= yi:
                        arr[y][x] = 0

    ans = arr.sum()
    print(ans)


def next_int():
    return int(next_str())


def next_str():
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a_x = 0
a_y = 0
b_x = W
b_y = 0
c_x = W
c_y = H
d_x = 0
d_y = H
area = 1

for l in li:
    if l[2] == 1:
        if l[0] >= b_x:
            area = 0
            break
        elif l[0] > a_x:
            a_x = l[0]
            d_x = l[0]
        
    elif l[2] == 2:
        if l[0] <= a_x:
            area = 0
            break
        elif l[0] < b_x:
            b_x = l[0]
            c_x = l[0]

    elif l[2] == 3:
        if l[1] >= d_y:
            area = 0
            break
        elif l[1] > a_y:
            a_y = l[1]
            b_y = l[1]
        
    elif l[2] == 4:
        if l[1] <= a_y:
            area = 0
            break
        elif l[1] < d_y:
            c_y = l[1]
            d_y = l[1]

if area != 0:
    area = (b_x - a_x)*(d_y - a_y)

print(area)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

w,h,n = [int(x) for x in stdin.readline().rstrip().split()]
board = [[1] * w for i in range(h)]
ans = 0

for i in range(n):
    x,y,a = [int(x) for x in stdin.readline().rstrip().split()]
    if a == 1:
        for j in range(h):
            for k in range(x):
                board[j][k] = 0
    elif a == 2:
        for j in range(h):
            for k in range(x,w):
                board[j][k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(w):
                board[j][k] = 0            
    elif a == 4:
        for j in range(y,h):
            for k in range(w):
                board[j][k] = 0

for i in range(h):
    ans += sum(board[i])

print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
a_list =[] 
for i in range(N):
  a_list.append(list(map(int, input().split())))
a1_list = [i[0] for i in a_list if i[2] == 1 ]
a2_list = [i[0] for i in a_list if i[2] == 2 ]
a3_list = [i[1] for i in a_list if i[2] == 3 ]
a4_list = [i[1] for i in a_list if i[2] == 4 ]
if a1_list == []:
  a1_max = 0
else:
  a1_max = max(a1_list)
if a2_list == []:
  a2_min = W
else:
  a2_min = min(a2_list)
if a3_list ==[]:
  a3_max = 0
else:
  a3_max = max(a3_list)
if a4_list == []:
  a4_min = H
else:
  a4_min = min(a4_list)
S = (a2_min - a1_max)*(a4_min - a3_max)
if (a2_min - a1_max) >= 0 and (a4_min - a3_max) >= 0:
  print(S)
else:
  print(0)

Submission status: Accepted

Solution code:
import sys
def 解():
    iW,iH,iN =[int(_) for _ in input().split()]
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    iU = iH
    iD = 0
    iL = 0
    iR = iW

    for x,y,a in aD:
        if a == 1:
            iL = max(iL,x)
        elif a == 2 :
            iR = min(iR,x)
        elif a == 3:
            iD = max(iD,y)
        elif a == 4:
            iU = min(iU,y)
    if iD > iU or iL > iR:
        print (0)
    else:
        print((iU-iD)*(iR-iL) )
解()

Submission status: Accepted

Solution code:
#! /usr/bin/python3
# すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)

"""
    白い部分を1, 黒い部分を0
"""
import numpy as np

test_mode = False

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

x_add = 0
y_add = 0
a_add = 0

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

arr_2d = np.ones((W, H))    # W×H のリスト（1で初期化）

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


for i in range(N):
    if a[i] == 1:
        arr_2d[:x[i], :] = 0
    if a[i] == 2:
        arr_2d[x[i]:, :] = 0
    if a[i] == 3:
        arr_2d[:, :y[i]] = 0
    if a[i] == 4:
        arr_2d[:, y[i]:] = 0

if test_mode:
    print(arr_2d)

print(np.sum(arr_2d == 1))


"""
    numpy使い方_2_スライスとブールインデックス
    http://ism1000ch.hatenablog.com/entry/2014/01/15/025328
    NumPyで全要素を同じ値で初期化した配列ndarrayを生成
    https://note.nkmk.me/python-numpy-zeros-ones-full/
"""

Submission status: Accepted

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

matrix = []
for j in range(h):
	line = []
	for i in range(w):
		line.append(0)
	matrix.append(line)

for k in range(n):
	x, y, a = map(int, input().split())
	if a == 1:
		for i in range(len(matrix)):
			for j in range(x):
				matrix[i][j] = 1
	elif a == 2:
		for i in range(len(matrix)):
			for j in range(x, len(matrix[0])):
				matrix[i][j] = 1
	elif a == 3:
		for i in range(y):
			for j in range(len(matrix[0])):
				matrix[i][j] = 1
	else:
		for i in range(y, len(matrix)):
			for j in range(len(matrix[0])):
				#print("i: ", i)
				#print("j: ", j)
				matrix[i][j] = 1

cnt = 0
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] == 0:
			cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(n)]
s, t = [0, w], [0, h]
for i in range(n):
    x = p[i][0]
    y = p[i][1]
    a = p[i][2]
    if a == 1:
        if x <= s[0]:
            continue
        elif s[0] < x < s[1]:
            s[0] = x
        else:
            print(0)
            exit()
    elif a == 2:
        if x <= s[0]:
            print(0)
            exit()
        elif s[0] < x < s[1]:
            s[1] = x
        else:
            continue
    elif a == 3:
        if y <= t[0]:
            continue
        elif t[0] < y < t[1]:
            t[0] = y
        else:
            print(0)
            exit()
    else:
        if y <= t[0]:
            print(0)
            exit()
        elif t[0] < y < t[1]:
            t[1] = y
        else:
            continue

print((s[1]-s[0])*(t[1]-t[0]))

Submission status: Accepted

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

xl = 0
xr = W
yu = H
yd = 0

for i 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)

ans = max(0,xr - xl) * max(0,yu - yd)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

xl = 0
xr = W
yu = H
yd = 0

for i 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)

ans = max(0,xr - xl) * max(0,yu - yd)

print(ans)

Submission status: Accepted

Solution code:
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 and xl<x:
        xl=x
    elif a==2 and xr>x:
        xr=x
    elif a==3 and yd<y:
        yd=y
    elif a==4 and yu>y:
        yu=y

print(max(0,(yu-yd))*max(0,(xr-xl)))

Submission status: Accepted

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

print(0 if ans == 0 else (W-tyoten[0])*(H-tyoten[1]))

Submission status: Accepted

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

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

for i in range(N):
    if a[i] == 1:
        if x_low < x[i]:
            x_low = x[i]
    if a[i] == 2:
        if x_high > x[i]:
            x_high = x[i]
    if a[i] == 3:
        if y_low < y[i]:
            y_low = y[i]
    if a[i] == 4:
        if y_high > y[i]:
            y_high = y[i]

if x_high < x_low or y_high < y_low:
    print(0)
else:
    print((x_high - x_low) * (y_high - y_low))

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 _ in [0]*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:
import numpy as np
h,w,n=map(int, input().split())
c=np.ones(h*w).reshape(w,h)
for i in range(n):
    x,y,a=map(int, input().split())
    if a==1:c[:,:x]=0
    if a==2:c[:,x:]=0
    if a==3:c[:y,:]=0
    if a==4:c[y:,:]=0
print(int(c.sum()))

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    W, H, N = map(int, input().split())
    field = [[0] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        min_y, max_y, min_x, max_x = 0, H, 0, W
        if a == 1:
            max_x = x
        elif a == 2:
            min_x = x
        elif a == 3:
            max_y = y
        elif a == 4:
            min_y = y

        for y in range(min_y, max_y):
            for x in range(min_x, max_x):
                field[y][x] = 1

    ans = 0
    for y in range(H):
        for x in range(W):
            ans += (field[y][x] == 0)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
count = 0
list_prob = []
while count < n:
    list_prob.append(list((map(int, input().split()))))
    count += 1
w_max = w
h_max = h
w_min = 0
h_min = 0

for row in list_prob:
    if row[2] == 1:
        if w_min < row[0]:
            w_min = row[0]
    elif row[2] == 2:
        if w_max > row[0]:
            w_max = row[0]
    elif row[2] == 3:
        if h_min < row[1]:
            h_min = row[1]
    else:
        if h_max > row[1]:
            h_max = row[1]
if w_max < w_min or h_max < h_min:
    print(0)
else:
    print((w_max - w_min)*(h_max - h_min))

Submission status: Accepted

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

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        S[:, :x] += 1
    elif a == 2:
        S[:, x:] += 1
    elif a == 3:
        S[:y, :] += 1
    elif a == 4:
        S[y:, :] += 1

print(len(S[S == 0]))

Submission status: Accepted

Solution code:
X,Y,n=map(int,input().split())
x=y=0
for i in range(n):
    a,b,c=map(int,input().split())
    if c==1 and x<a:x=a
    if c==2 and X>a:X=a
    if c==3 and y<b:y=b
    if c==4 and Y>b:Y=b
print(max(X-x,0)*max(Y-y,0))

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

w, h, n = [int(i) for i in input().split()]
x1 = 0
x2 = w
y1 = 0
y2 = h
for i in range(n):
    xi, yi, ai = [int(i) for i in input().split()]
    if ai == 1:
        x1 = max(x1, xi)
    elif ai == 2:
        x2 = min(x2, xi)
    elif ai == 3:
        y1 = max(y1, yi)
    else:
        y2 = min(y2, yi)

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

Submission status: Accepted

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

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

xmin = 0
xmax = w
ymin = 0
ymax = h

ans = 0

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

for i in range(n):
    if a[i] == 1:
        if x[i] > xmin:
            xmin = x[i]
        
    elif a[i] == 2:
        if x[i] < xmax:
            xmax = x[i]

    elif a[i] == 3:
        if y[i] > ymin:
            ymin = y[i]

    else:
        if y[i] < ymax:
            ymax = y[i]

#print(xmax)
#print(xmin)
#print(ymax)
#print(ymin)

if (xmax - xmin) <= 0 or (ymax - ymin) <= 0:
    ans = 0
    
else:
    ans = (xmax - xmin) * (ymax - ymin)

print(ans)

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
xa=[0]
xb=[w]
ya=[0]
yb=[h]
for i in range(n):
  x1,y1,a1=map(int,input().split())
  if a1==1:
    xa.append(x1)
  elif a1==2:
    xb.append(x1)
  elif a1==3:
    ya.append(y1)
  elif a1==4:
    yb.append(y1)

if min(xb)<=max(xa) or min(yb)<=max(ya):
  print(0)
else:
  print((min(xb)-max(xa))*(min(yb)-max(ya)))

Submission status: Accepted

Solution code:
W,H,N=map(int, input().split())
ls1=[0]
ls2=[W]
ls3=[0]
ls4=[H]
for i in range(N):
    tmp=list(map(int, input().split()))
    if tmp[2]==1:
        ls1.append(tmp[0])
    if tmp[2]==2:
        ls2.append(tmp[0])
    if tmp[2]==3:
        ls3.append(tmp[1])
    if tmp[2]==4:
        ls4.append(tmp[1])
print((min(ls2)-max(ls1))*(min(ls4)-max(ls3)) if min(ls2)>=max(ls1) and min(ls4)>=max(ls3) else 0)

Submission status: Accepted

Solution code:
W,H,N = map(int,input().split())
W1 = []
W2 = []
H1 = []
H2 = []
W1.append(0)
W2.append(W)
H1.append(0)
H2.append(H)
for i in range(N) :
    x,y,a = map(int,input().split())
    if a == 1 :
        W1.append(x)
    if a == 2 :
        W2.append(x)
    if a == 3 :
        H1.append(y)
    if a == 4 :
        H2.append(y)
width = max(0,min(W2)-max(W1))
height = max(0,min(H2)-max(H1))
print(width*height)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        left  = max(left,x)
    if a == 2:
        right = min(right,x)
    if a == 3:
        up   = max(up,y)
    if a == 4:
        down = min(down,y)

w = max(0,right-left)
h = max(0,down-up)

print(w*h)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a1=[0];a2=[w];a3=[0];a4=[h]
for i in a:
  if i[2]==1:a1.append(i[0])
  else:pass
for i in a:
  if i[2]==2:a2.append(i[0])
  else:pass
for i in a:
  if i[2]==3:a3.append(i[1])
  else:pass
for i in a:
  if i[2]==4:a4.append(i[1])
  else:pass
if max(a1)-min(a2)<0:x=max(a1)-min(a2)
else:x=0
if max(a3)-min(a4)<0:y=max(a3)-min(a4)
else:y=0
print(x*y)

Submission status: Accepted

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

x_max, x_min, y_max, y_min = W, 0, H, 0

for i in range(N):
    if input_list[i][2] == 1:
        x_min = max(x_min, input_list[i][0])
    elif input_list[i][2] == 2:
        x_max = min(x_max, input_list[i][0])
    elif input_list[i][2] == 3:
        y_min = max(y_min, input_list[i][1])
    elif input_list[i][2] == 4:
        y_max = min(y_max, input_list[i][1])

if x_max - x_min > 0 and y_max - y_min > 0:
    print((x_max-x_min)*(y_max-y_min))
else:
    print(0)

Submission status: Accepted

Solution code:
def solve():
  x_max, y_max, N_max = map(int, input().split())
  x_min, y_min = 0, 0
  area = x_max * y_max
  W, H, N = [], [], []
  for i in range(N_max):
    x, y, a = map(int, input().split())
    if a == 1 and x_min < x:
      x_min = x
    elif a == 2 and x_max > x:
      x_max = x
    elif a == 3 and y_min < y:
      y_min = y
    elif a == 4 and y_max > y:
      y_max = y

  if x_max <= x_min or y_max <= y_min:
    print(0)
  else:
    print((x_max - x_min) * (y_max - y_min))

solve()

Submission status: Accepted

Solution code:
w,h,n = map(int,input().split())
grid = [[1 for i in range(w)] for k 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):
                grid[j][k] = 0
    elif a == 2:
        for j in range(h):
            for k in range(x,w):
                grid[j][k] = 0
    elif a == 3:
        for j in range(y):
            for k in range(w):
                grid[j][k] = 0
    elif a == 4:
        for j in range(y,h):
            for k in range(w):
                grid[j][k] = 0

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

Submission status: Accepted

Solution code:
w, h, n = map(int, input().split())
x, y, a = [], [], []
m1 = [0, 0]
m2 = [w, h]
for _ in range(n):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)
for i in range(n):
    if a[i] == 1:
        m1[0] = max(m1[0], x[i])
    elif a[i] == 2:
        m2[0] = min(m2[0], x[i])
    elif a[i] == 3:
        m1[1] = max(m1[1], y[i])
    else:
        m2[1] = min(m2[1], y[i])
s = max(0, (m2[0] - m1[0])) * max(0, (m2[1] - m1[1]))
print(s)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
ans = 0
tyoten = [0, 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:
        if W <= x[i]:
            ans = 1
            break
        elif tyoten[0] < x[i] < W:
            tyoten[0] = x[i]
        
    if a[i] == 2:
        if x[i] <= tyoten[0]:
            ans = 1
            break
        elif tyoten[0] < x[i] < W:
            W = x[i]
    
    if a[i] == 3:
        if H <= y[i]:
            ans = 1
            break
        elif tyoten[1] < y[i] < H:
            tyoten[1] = y[i]
    
    if a[i] == 4:
        if y[i] <= tyoten[1]:
            ans = 1
            break
        elif tyoten[1] < y[i] < H:
            H = y[i]
        
if ans == 1:
    print(0)
else:
    print((W-tyoten[0])*(H-tyoten[1]))

Submission status: Accepted

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

memox = [True]*(w+1)
memoy = [True]*(h+1)


for i in range(n):
    xi,yi,a=map(int, input().split())
    if a == 1:
        memox = [False] * xi + memox[xi:]
    elif a == 2:
        memox = memox[:xi+1] + [False] * (w - xi)
    elif a == 3:
        memoy = [False] * yi + memoy[yi:]
    elif a == 4:
        memoy = memoy[:yi+1] + [False] * (h - yi)
memox = [i for i in memox if i]
memoy = [i for i in memoy if i]

if memox and memoy:
    print(max([0, (len(memox) - 1) * (len(memoy) - 1)]))
else:
    print(0)

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)

xmin = 0
xmax = w
ymin = 0
ymax = h

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

if xmin > xmax or ymax < ymin:
    print(0)
else:
    print((xmax - xmin) * (ymax - ymin))

Submission status: Accepted

Solution code:
import sys
sdin = sys.stdin.readline

w,h,n = map(int, sdin().split())
xy = [[0], [w], [0], [h]]
for _ in range(n):
    x,y,a = map(int, sdin().split())
    if a-1 < 2:
        xy[a-1].append(x)
    else:
        xy[a-1].append(y)
    
x_min = max([xy[0][i] for i in range(len(xy[0]))])
x_max = min([xy[1][i] for i in range(len(xy[1]))])
y_min = max([xy[2][i] for i in range(len(xy[2]))])
y_max = min([xy[3][i] for i in range(len(xy[3]))])

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

Submission status: Accepted

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

top = H
btm = 0
left = 0
right = W
for x,y,a in src:
    if a == 1:
        left = max(left,x)
    elif a == 2:
        right = min(right,x)
    elif a == 3:
        btm = max(btm,y)
    else:
        top = min(top,y)
w = max(0, right-left)
h = max(0, top-btm)
print(w*h)

Submission status: Accepted

Solution code:
W,H,N=[int(i) for i in input().split()]
l,r,u,d = 0,W,0,H

for i in range(N):
	x,y,a=[int(i) for i in input().split()]
	if a==1:
		l=max(l,x)
	if a==2:
		r=min(r,x)
	if a==3:
		u=max(u,y)
	if a==4:
		d=min(d,y)
h=max(0,d-u)
w=max(0,r-l)

print(h*w)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    W, H, N = li_input()
    G = [[1] * W for _ in range(H)]

    for i in range(N):
        x, y, a = li_input()

        if a == 1:
            for i in range(H):
                for j in range(x):
                    G[i][j] = 0

        if a == 2:
            for i in range(H):
                for j in range(x, W):
                    G[i][j] = 0

        if a == 3:
            for i in range(y):
                for j in range(W):
                    G[i][j] = 0

        if a == 4:
            for i in range(y, H):
                for j in range(W):
                    G[i][j] = 0

    ans = 0

    for row in G:
        ans += sum(row)

    print(ans)


main()