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:
import sys

w,h,n = (int(_) for _ in input().split())
xa = ya = 0
xb = w
yb = h

for i in range(n):
    x,y,a=(int(_) for _ in input().split())
    if(a == 1):
        if(x > xa):
            xa = x
    elif (a == 2):
        if (x < xb):
            xb = x
    elif (a == 3):
        if (y > ya):
            ya = y
    elif (a == 4):
        if (y < yb):
            yb = y
    else:
        sys,exit(1)


xx = xb-xa
yy = yb-ya
ans = (xb-xa)*(yb-ya)
print('0') if (ans < 0) or (xx < 0) or(yy < 0) else print(ans)

Submission status: Accepted

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

for x in range(n):
    x, y, a = map(int, input().split())
    for idx_y, yy in enumerate(lst):
        for idx_x, _ in enumerate(yy):
            if a == 1 and idx_x < x:
                lst[idx_y][idx_x] = 0
            elif a == 2 and idx_x >= x:
                lst[idx_y][idx_x] = 0
            elif a == 3 and idx_y < y:
                lst[idx_y][idx_x] = 0
            elif a == 4 and idx_y >= y:
                lst[idx_y][idx_x] = 0

print(sum([sum(x) for x in lst]))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
h = {1: 0, 2: W, 3: 0, 4: H}
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        h[a] = max(h[a], x)
    elif a == 2:
        h[a] = min(h[a], x)
    elif a == 3:
        h[a] = max(h[a], y)
    else:
        h[a] = min(h[a], y)
ans = W * H
ans -= H * (h[1] + W-h[2])
ans -= max(0, (W - (h[1] + W-h[2]))) * (h[3] + H-h[4])
print(max(ans, 0))

Submission status: Accepted

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

def main():
    w, h, n = map(int, input().split())
    arry = [list(map(int, input().split())) for _ in range(n)]

    x1 = 0
    x2 = w
    y1 = 0
    y2 = h
    for i in arry:
        if i[2] == 1:
            x1 = max(x1, i[0])
        elif i[2] == 2:
            x2 = min(x2, i[0])
        elif i[2] == 3:
            y1 = max(y1, i[1])
        elif i[2] == 4:
            y2 = min(y2, i[1])
    if x2 <= x1 or y2 <= y1:
        ans = 0
    else:
        ans = (x2 - x1) * (y2 - y1)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 12 13:14:59 2018
ABC047B
@author: maezawa
"""
w, h, n = list(map(int, input().split()))
xl = 0
xu = w
yl = 0
yu = h

for i in range(n):
    xi, yi, ai = list(map(int, input().split()))
    if ai == 1:
        if xl < xi:
            xl = xi
    elif ai == 2:
        if xu > xi:
            xu = xi
    elif ai == 3:
        if yl < yi:
            yl = yi
    else:
        if yu > yi:
            yu = yi
if xl<=xu and yl<=yu:
    ans = (xu-xl)*(yu-yl)
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
#47b
w,h,n = map(int,input().split())
x,y=0,0

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

print(0 if x>=w or y>=h else (w-x)*(h-y))

Submission status: Accepted

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

z = np.zeros( (H, W) )
#print(z)

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

  if a == 1:
    z[:, :x] = 1

  if a == 2:
    z[:, x:] = 1

  y = H - y
  if a == 3:
    z[y:,:] = 1
  
  if a == 4:
    z[:y,:] = 1
#print(z)

ans = int(W*H - z.sum())
print(ans)

Submission status: Accepted

Solution code:
W,H,n=map(int,input().split())
l=[[0 for i in range(W)] for j in range(H)] 
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1: #x<xi
    for i in range(H):
      for j in range(x):
        l[i][j]=1
  elif a==2: #x>xi
    for i in range(H):
      for j in range(x,W):
        l[i][j]=1
  elif a==3: #y<yi
    for i in range(y):
      for j in range(W):
        l[i][j]=1
  else: #y>yi
    for i in range(y,H):
      for j in range(W):
        l[i][j]=1
print(W*H-sum([sum(i) for i in l]))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())
x,y = 0,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(" "))
x_y_a = [tuple(map(int, input().split(" "))) for i in range(n)]

min_x, max_x, min_y, max_y = 0, w, 0, h
for x_y_a_i in x_y_a:
    x, y, a = x_y_a_i
    if a == 1:
        min_x = max(min_x, x)
    elif a == 2:
        max_x = min(max_x, x)
    elif a == 3:
        min_y = max(min_y, y)
    elif a == 4:
        max_y = min(max_y, y)

print(max(0, max_x-min_x) * max(0, max_y-min_y))

Submission status: Accepted

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

min_x, max_x, min_y, max_y = 0, w, 0, h
for x_y_a_i in x_y_a:
    x, y, a = x_y_a_i
    if a == 1:
        min_x = max(min_x, x)
    elif a == 2:
        max_x = min(max_x, x)
    elif a == 3:
        min_y = max(min_y, y)
    elif a == 4:
        max_y = min(max_y, y)

print(0 if min_x > max_x or min_y > max_y else (max_x-min_x) * (max_y-min_y))

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:
WHN=input()
WHN=WHN.rstrip().split(" ")
W=int(WHN[0])
H=int(WHN[1])
N=int(WHN[2])

list1=[]
for i in range(H):
    list2=[]
    for j in range(W):
        list2.append('w')
    list1.append(list2)
    list2=[]
#print(list1)

i=0
for i in range(N):
    xya=input()
    xya=xya.rstrip().split(" ")
    x=int(xya[0])
    y=int(xya[1])
    a=int(xya[2])
    #print(x,y,a)
    if a==1:
        j=0
        for j in range(H):
            k=0
            for k in range(W):
                if k<x:
                    list1[j][k]='b'
    elif a==2:
        j=0
        for j in range(H):
            k=0
            for k in range(W):
                if k+1>x:
                    list1[j][k]='b'
    elif a==3:
        j=0
        for j in range(H):
            k=0
            for k in range(W):
                if j<y:
                    list1[j][k]='b'
    elif a==4:
        j=0
        for j in range(H):
            k=0
            for k in range(W):
                if j+1>y:
                    list1[j][k]='b'
                    #print(list1)
                    
count=0
i=0
for i in range(H):
    k=0
    for j in range(W):
        if list1[i][j]=='w':
            count+=1
print(count)

Submission status: Accepted

Solution code:
fn = lambda: map(int, input().split())
W, H, N = fn()
min_x, max_x = 0, W
min_y, max_y = 0, H
for i in range(N):
    xi, yi, ai = fn()
    if ai == 1:
        min_x = max(xi, min_x)
    elif ai == 2:
        max_x = min(xi, max_x)
    elif ai == 3:
        min_y = max(yi, min_y)
    elif ai == 4:
        max_y = min(yi, max_y)
    else:
        print('Something wrong')

print(max(max_x - min_x, 0) * max(max_y - min_y, 0))

Submission status: Accepted

Solution code:
# utf-8:
import numpy as np


def main():
    w, h, n = map(int, raw_input().split())
    sq = np.ones((h, w))
    for _ in range(n):
        x, y, a = map(int, raw_input().split())
        paint(sq, x, y, a, w, h)

    print(int(sq.sum()))



def paint(sq, x, y, a, w, h):
    if a == 1:
        for i in range(x):
            sq[:, i] = 0
    elif a == 2:
        for i in range(w - x):
            sq[:, i + x] = 0
    elif a == 3:
        for i in range(y):
            sq[i, :] = 0
    elif a == 4:
        for i in range(h - y):
            sq[i + y, :] = 0


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
W, H ,N = list(map(int, input().split()))
S = [[1]*W] * H

for i in range(N):
    x, y, a =  list(map(int, input().split()))
    if a == 3:
        for j in range(y):
            S[j] = [0] * W
    elif a == 4:
        for j in range(y, H):
            S[j] = [0] * W
    elif a == 1:
        for j in range(H):
            for k in range(x):
                S[j][k] = 0
    elif a == 2:
        for j in range(H):
            for k in range(x, W):
                S[j][k] = 0

re = 0
for i in range(H):
    re += sum(S[i])

print(re)

Submission status: Accepted

Solution code:
fn = lambda: map(int, input().split())
W, H, N = fn()
A = [[1 for _ in range(W)] for _ in range(H)]
for _ in range(N):
    x, y, a = fn()
    if a == 1:
        for i in range(H):
            for j in range(x):
                A[i][j] = 0
    elif a == 2:
        for i in range(H):
            for j in range(x, W):
                A[i][j] = 0
    elif a == 3:
        for i in range(W):
            for j in range(y):
                A[j][i] = 0
    elif a == 4:
        for i in range(W):
            for j in range(y, H):
                A[j][i] = 0
    else:
        print('Something wrong')

print(sum([sum(Ai) for Ai in A]))

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split(" "))
sq = []
for i in range(H):
    sq.append([1] * W)

for i in range(N):
    x, y, a = map(int, input().split(" "))
    if a == 1:
        for i, w in enumerate(sq):
            for j, h in enumerate(w):
                if j < x:
                    sq[i][j] = 0
    if a == 2:
        for i, w in enumerate(sq):
            for j, h in enumerate(w):
                if j >= x:
                    sq[i][j] = 0

    if a == 3:
        for i, w in enumerate(sq):
            for j, h in enumerate(w):
                if i < y:
                    sq[i][j] = 0
    if a == 4:
        for i, w in enumerate(sq):
            for j, h in enumerate(w):
                if i >= y:
                    sq[i][j] = 0
area = 0
for w in sq:
    for h in w:
        area += h
print(area)

Submission status: Accepted

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

Submission status: Accepted

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

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

for _ in range(N):
    x, y, a = map(int, input().split())
    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)

dx = max(0, (x2 - x1))
dy = max(0, (y2 - y1))

print(dx * dy)

Submission status: Accepted

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

rect = [(p%W, p//W) for p in range(W*H)]
for i in range(N):
    xi, yi, ai = map(int, input().split())
    if(ai==1):
        cond = lambda x_y: x_y[0] >= xi
    elif(ai==2):
        cond = lambda x_y: x_y[0] < xi
    elif(ai==3):
        cond = lambda x_y: x_y[1] >= yi
    else:
        cond = lambda x_y: x_y[1] < yi
    rect = list(filter(cond , rect))
        
print(len(rect))

Submission status: Accepted

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

Submission status: Accepted

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

ma_x=w
ma_y=h
mi_x=0
mi_y=0

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if mi_x<x:
            mi_x=x
    elif a==2:
        if ma_x>x:
            ma_x=x
    elif a==3:
        if mi_y<y:
            mi_y=y
    elif a==4:
        if ma_y>y:
            ma_y=y

if ma_x-mi_x<0 and ma_y-mi_y<0:
  ma_x=mi_x
            
ans=(ma_x-mi_x)*(ma_y-mi_y)

if ans<0:
    ans=0

print(ans)

Submission status: Accepted

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

s = [[1 for j in range(w)] for i in range(h)]

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

    if a == 1:
        for m in range(h):
            for n in range(x):
                s[m][n] = 0
    elif a == 2:
        for m in range(h):
            for n in range(x, w):
                s[m][n] = 0
    elif a == 3:
        for m in range(y):
            for n in range(w):
                s[m][n] = 0
    elif a == 4:
        for m in range(y, h):
            for n in range(w):
                s[m][n] = 0

print(sum(map(sum, s)))

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
y=[0,w]
t=[0,h]
def ct(w0,h0,a0):
  if a0==1:
    v=max(w0,y[0])
    y[0]=v
  if a0==2:
    v=min(w0,y[1])
    y[1]=v
  if a0==3:
    v=max(h0,t[0])
    t[0]=v
  if a0==4:
    v=min(h0,t[1])
    t[1]=v
for i in range(n):
  w1,h1,a1=map(int,input().split())
  ct(w1,h1,a1)

print(max(0,y[1]-y[0])*max(0,t[1]-t[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())))

a1 = [0]
a2 = [W]
a3 = [0]
a4 = [H]
for x,y,a in XYA:
    if a==1:
        a1.append(x)
    elif a==2:
        a2.append(x)
    elif a==3:
        a3.append(y)
    elif a==4:
        a4.append(y)
        
x_min = max(a1)
x_max = min(a2)
y_min = max(a3)
y_max = min(a4)

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

print(max(0,ans))

Submission status: Accepted

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

for _ in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        for xx in range(x):
            for yy in range(h):
                rect[xx][yy] = 0
    elif a == 2:
        for xx in range(x, w):
            for yy in range(h):
                rect[xx][yy] = 0
    elif a == 3:
        for xx in range(w):
            for yy in range(y):
                rect[xx][yy] = 0
    else:
         for xx in range(w):
             for yy in range(y, h):
                 rect[xx][yy] = 0

ans = 0
for xx in range(w):
    for yy in range(h):
        ans += rect[xx][yy]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

p1 = [0, 0]
p2 = [w, h]

for i in range(n):
    if a[i] == 1:
        p1[0] = max(p1[0], x[i])
    elif a[i] == 2:
        p2[0] = min(p2[0], x[i])
    elif a[i] == 3:
        p1[1] = max(p1[1], y[i])
    else:
        p2[1] = min(p2[1], y[i])

if p1[0] >= p2[0] or p1[1] >= p2[1]:
    print(0)
else:
    print((p2[0] - p1[0]) * (p2[1] - p1[1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w,h,n=map(int,input().split())
t=[list(map(int,input().split()))for i in range(n)]
x_left=0
x_right=w
y_low=0
y_hight=h
for i in range(n):
    if t[i][2]==1:
        if x_left<=t[i][0]:
            x_left=t[i][0]
    elif t[i][2]==2:
        if t[i][0]<=x_right:
            x_right=t[i][0]
    elif t[i][2]==3:
        if y_low<=t[i][1]:
            y_low=t[i][1]
    elif t[i][2]==4:
        if t[i][1]<=y_hight:
            y_hight=t[i][1]
if x_right<=x_left or y_hight<=y_low:
    print(0)
else:
    print((x_right-x_left)*(y_hight-y_low))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
R=[0,0,W,0,H]
for _ in[0]*N:
    *wh,a=map(int,input().split())
    R[a]=eval(['min','max'][a%2]+'(R[a],wh[a//3])')
_,w,W,h,H=R
print((W-w)*(H-h)*(W>w)*(H>h))

Submission status: Accepted

Solution code:
W,H,N=map(int,input().split())
R=[0,0,W,0,H]
for _ in[0]*N:
    *wh,a=map(int,input().split())
    R[a]=[min(R[a],wh[a//3]),max(R[a],wh[a//3])][a%2]
_,w,W,h,H=R
print((W-w)*(H-h)*(W>w)*(H>h))

Submission status: Accepted

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

Submission status: Accepted

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

w, h, n = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
field = [['.' for j in range(w)] for i in range(h)]
for a in A:
    if a[2] == 1:
        for i in range(h):
            for j in range(a[0]):
                field[i][j] = '#'
    elif a[2] == 2:
        for i in range(h):
            for j in range(a[0], w):
                field[i][j] = '#'
    elif a[2] == 3:
        for i in range(a[1]):
            for j in range(w):
                field[i][j] = '#'
    elif a[2] == 4:
        for i in range(a[1], h):
            for j in range(w):
                field[i][j] = '#'
ans = 0
for line in field:
    ans += line.count('.')
print(ans)

Submission status: Accepted

Solution code:
W, H, N = map(int, input().split())    
xya_list = [list(map(int, input().split())) for  _ in range(N)]
x_lower, x_upper, y_lower, y_upper =0, W,  0, H
for i in xya_list:
    if i[2] == 1 and i[0] > x_lower:
        x_lower = i[0]
    elif i[2] == 2 and i[0] < x_upper:
        x_upper = i[0]
    elif i[2] == 3 and i[1] > y_lower:
        y_lower = i[1]
    elif i[2] == 4 and i[1] < y_upper:
        y_upper = i[1]

area = (x_upper - x_lower) * (y_upper - y_lower)
if x_upper - x_lower > 0 and y_upper - y_lower > 0:
    print(area)
else:
    print(0)

Submission status: Accepted

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

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

# 1マスずつ塗りつぶさないパターン(こっちのが速い)
minXY = [0, 0]
maxXY = [W, H]
for i in range(N):
    
    if aN[i][2] == 1:
        minXY[0] = max(minXY[0], aN[i][0])

    elif aN[i][2] == 2:
        maxXY[0] = min(maxXY[0], aN[i][0])

    elif aN[i][2] == 3:
        minXY[1] = max(minXY[1], aN[i][1])

    elif aN[i][2] == 4:
        maxXY[1] = min(maxXY[1], aN[i][1])

# 縦横それぞれにマイナスの可能性を考慮する
ansW = maxXY[0] - minXY[0]
ansH = maxXY[1] - minXY[1]
if ansW < 0:
    ansW = 0
if ansH < 0:
    ansH = 0

print(ansH * ansW)

Submission status: Accepted

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

W, H, N = map(int, input().split())
HW = [[0 for i in range(W)] for j in range(H)]

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

for i in range(N):

    if aN[i][2] == 1:
        for j in range(H):
            for k in range(aN[i][0]):
                HW[j][k] = 1

    elif aN[i][2] == 2:
        for j in range(H):
            for k in range(aN[i][0], W):
                HW[j][k] = 1

    elif aN[i][2] == 3:
        for j in range(aN[i][1]):
            for k in range(W):
                HW[j][k] = 1

    elif aN[i][2] == 4:
        for j in range(aN[i][1], H):
            for k in range(W):
                HW[j][k] = 1

ans = 0
for i in range(H):
    ans += HW[i].count(0)
print(ans)

Submission status: Accepted

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

res = 0
x_1, x_2, y_1, y_2 = 0, w, 0, h
for a in nums:
  if a[2] == 1:
    if a[0] > x_1:
      x_1 = a[0]
  elif a[2] == 2:
    if a[0] < x_2:
      x_2 = a[0]
  elif a[2] == 3:
    if a[1] > y_1:
      y_1 = a[1]
  elif a[2] == 4:
    if a[1] < y_2:
      y_2 = a[1]
if x_2 <= x_1 or y_2 <= y_1:
  print(0)
else:
  print((y_2-y_1)*(x_2-x_1))

Submission status: Accepted

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

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

Submission status: Accepted

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

points_dir = []
for i in range(n):
  points_dir.append(list(map(int, input().split())))


left_lim = 0
right_lim = w
bottom_lim = 0
top_lim = h

for i in range(n):
  if points_dir[i][2] == 1:
    left_lim = points_dir[i][0] if points_dir[i][0] > left_lim else left_lim
  elif points_dir[i][2] == 2:
    right_lim = points_dir[i][0] if points_dir[i][0] < right_lim else right_lim
  elif points_dir[i][2] == 3:
    bottom_lim = points_dir[i][1] if points_dir[i][1] > bottom_lim else bottom_lim
  elif points_dir[i][2] == 4:
    top_lim = points_dir[i][1] if points_dir[i][1] < top_lim else top_lim

if right_lim - left_lim < 0 or top_lim - bottom_lim < 0:
  print("0")
else:
  print((right_lim - left_lim) * (top_lim - bottom_lim))

Submission status: Accepted

Solution code:
def solve(W,H,N):
    B = [[1 for i in range(W)] for j in range(H)]
    for i in range(N):
        x,y,a =[int(j) for j in input().split(' ')]
        i
        if a==1:
            for j in range(x):
                for k in range(H):
                    B[k][j]=0
        if a==2:
            for j in range(x,W):
                for k in range(H):
                    B[k][j]=0
        if a==3:
            for j in range(y):
                B[j] =[0]*W
        if a==4:
            for j in range(y,H):
                B[j] =[0]*W
    #print(B)
    c =0
    for i in range(W):
        for j in range(H):
            if B[j][i] ==1:
                c +=1
    print(c)
W,H,N = [int(i) for i in input().split(' ')]

solve(W,H,N)

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())))

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

print(x.count(False)*y.count(False))

Submission status: Accepted

Solution code:
[w,h,n]=[int(i) for i in input().split()]
a=[]
for i in range(n):
    a.append([int(j) for j in input().split()])
#それぞれのマスを左下の座標で管理
#(0,0)から(w-1,h-1)まで
#print(a)
b=[]
for i in range(w):
    for j in range(h):
        b.append([i,j])
#print(b)
#全ての入力について、大小で外していく
for i in range(n):
    if a[i][2]==1:
        for j in range(w*h):
            if b[j][0]<a[i][0]:
                b[j]=[-10,-10]
    elif a[i][2]==2:
        for j in range(w*h):
            if b[j][0]>=a[i][0]:
                b[j]=[-10,-10]
    elif a[i][2]==3:
        for j in range(w*h):
            if b[j][1]<a[i][1]:
                b[j]=[-10,-10]
    elif a[i][2]==4:
        for j in range(w*h):
            if b[j][1]>=a[i][1]:
                b[j]=[-10,-10]
#print(b)
c=[i for i in b if i!=[-10,-10]]
#print(c)
print(len(c))

Submission status: Accepted

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

upright = [W,H]
downleft = [0,0]

for i in range(N):
    x,y,a = (int(k) for k in input().split())
    if a == 1:
        if x >= downleft[0]:
            downleft[0] = x
    elif a == 2:
        if x <= upright[0]:
            upright[0] = x
    elif a == 3:
        if y >= downleft[1]:
            downleft[1] = y
    else:
        if y <= upright[1]:
            upright[1] = y

height = upright[1]-downleft[1]
width = upright[0]-downleft[0]

if height >= 0 and width >= 0:
    area = height*width
else:
    area = 0

print(area)

Submission status: Accepted

Solution code:
import numpy as np
w,h,n=map(int,raw_input().split())
mp = np.zeros((w,h))
for i in range(n):
  xi,yi,ai=map(int,raw_input().split())
  if ai==1: # x < xi
    mp[:xi,:] = 1
  elif ai==2: # x > xi
    mp[xi:,:] = 1
  elif ai==3: # y < yi
    mp[:,:yi] = 1
  elif ai==4: # y > yi
    mp[:,yi:] = 1
print w*h - np.sum(mp)

Submission status: Accepted

Solution code:
w,h,n = map(int, input().split())
b = [[0]*(w+1) for _ in range(h+1)]

for _ in range(n):
    x,y,a = map(int, input().split())
    if a <= 2:
        f = 0 if a == 1 else x
        t = x if a == 1 else w
        b[0][f] += 1
        b[0][t] -= 1
    else:
        f = 0 if a == 3 else y
        t = y if a == 3 else h
        b[f][0] += 1
        b[t][0] -= 1

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

Submission status: Accepted

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

Submission status: Accepted

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

low_left_x = 0
low_left_y = 0
s = 0

for i in range(N):
    if points[i][2] == 1:
        if points[i][0] > low_left_x:
            low_left_x = points[i][0]
    elif points[i][2] == 2:
        if points[i][0] < W:
            W = points[i][0]
    elif points[i][2] == 3:
        if points[i][1] > low_left_y:
            low_left_y = points[i][1]
    elif points[i][2] == 4:
        if points[i][1] < H:
            H = points[i][1]
    
    if W<low_left_x:
        W = low_left_x
    if H < low_left_y:
        H = low_left_x

s = (W-low_left_x)*(H-low_left_y)
print(s)

Submission status: Accepted

Solution code:

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

for i in range(N):
    selection = points[i][2]
    if selection == 1:
        for j in range(0,H):
            for k in range(0, points[i][0]):
                mesh[j][k] = 1
    elif selection == 2:
        for j in range(0,H):
            for k in range(points[i][0], W):
                mesh[j][k] = 1
    elif selection == 3:
        for j in range(0, points[i][1]):
            for k in range(0,W):
                mesh[j][k] = 1
    elif selection == 4:
        for j in range(points[i][1], H):
            for k in range(0,W):
                mesh[j][k] = 1
    else:
        print("invalid value!")

colored_sum = 0
for i in range(H):
    colored_sum += sum(mesh[i])

white_sum = W*H - colored_sum
print(white_sum)

Submission status: Accepted

Solution code:
e,n,N = map(int,input().split())
w=s=0
for _ in[0]*N:
    x,y,a = map(int,input().split())
    if a == 1:
        w = max(w,x)
    elif a == 2:
        e = min(e,x)
    elif a == 3:
        s = max(s,y)
    else:
        n = min(n,y)
print((e-w)*(n-s)*(e>w)*(n>s))

Submission status: Accepted

Solution code:
W, H, N = (int(i) for i in input().split())
points = [[int(i) for i in input().split()] for i in range(N)]
low_left_x = 0
low_left_y = 0
s = 0
j = 0

for j in range(N):
    if(points[j][2] == 1): #blanking left
        if(points[j][0] > low_left_x):
            low_left_x = points[j][0]
    elif(points[j][2] == 2): #blanking right
        if(points[j][0] < W):
            W = points[j][0]
    elif(points[j][2] == 3): #blanking low
        if(points[j][1] > low_left_y):
            low_left_y = points[j][1]
    elif(points[j][2] == 4): #blanking high
        if(points[j][1] < H):
            H = points[j][1]
    
    if(W < low_left_x):
        W = low_left_x
    if(H < low_left_y):
        H = low_left_y

s = (W - low_left_x) * (H - low_left_y)
print(s)

Submission status: Accepted

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