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: Wrong Answer

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

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

show_flg=False
show_flg=True

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

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

Submission status: Wrong Answer

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

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

show_flg=False
show_flg=True

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

print((X-x)*(Y-y))

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

squea = (x_max - x_min) * (y_max - y_min)

print(squea)

Submission status: Wrong Answer

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

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

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

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

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

print((w-x_min)*(h-y_min))

Submission status: Wrong Answer

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

#領域を更新していく
for i in l:
    if i[-1]==1:
        S-=ab(i[0],x_min)*ab(h,y_min)
        x_min=i[0]

    elif i[-1]==2:
        S-=ab(w,i[0])*ab(h,y_min)
        w=i[0]

    elif i[-1]==3:
        S-=ab(i[1],y_min)*ab(w,x_min)
        y_min=i[1]

    else:
        S-=ab(h,i[1])*ab(w,x_min)
        h=i[1]

print(S if S>=0 else 0)

Submission status: Wrong Answer

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

#領域を更新していく
for i in l:
    if i[-1]==1:
        S-=(i[0]-x_min)*(h-y_min)
        x_min=i[0]

    elif i[-1]==2:
        S-=(w-i[0])*(h-y_min)
        w=i[0]

    elif i[-1]==3:
        S-=(i[1]-y_min)*(w-x_min)
        y_min=i[1]

    else:
        S-=(h-i[1])*(w-x_min)
        h=i[1]
print(S if S>=0 else 0)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
w,h,n=map(int,input().split())
x1=0
x2=w
y1=0
y2=h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x1,x)
    if a==2:
        x2=min(x2,x)
    if a==3:
        y1=max(y1,y)
    if a==4:
        y2=min(y2,y)
print(max((x2-x1)*(y2-y1),0))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
w,h,n=map(int,input().split())
x1=0
x2=w
y1=0
y2=h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x1,x)
    if a==2:
        x2=max(x2,x)
    if a==3:
        y1=max(y1,y)
    if a==2:
        y2=max(y2,y)
print(max((x2-x1)*(y2-y1),0))

Submission status: Wrong Answer

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

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

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

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

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

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

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

print(S)

Submission status: Wrong Answer

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

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

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

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

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

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

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

print(S)

Submission status: Wrong Answer

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

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

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

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

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

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

# 負になった場合は0にする
S = max((w2-w1) * (h2-h1) , 0)
print(S)

Submission status: Wrong Answer

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

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

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

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

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

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

# 負になった場合は0にする
S = max((w2-w1) * (h2-h1) , 0)
print(S)

Submission status: Wrong Answer

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

for i in range(N):
  li.append(list(map(int,input().split())))

s = [[0, W], [0, H]]

for x in li:
  if x[2] == 1:
    if s[0][0] < x[0]:
      s[0][0] = x[0]
  
  if x[2] == 2:
    if s[0][1] > x[0]:
      s[0][1] = x[0]
  
  if x[2] == 3:
    if s[1][0] < x[1]:
      s[1][0] = x[1]
  
  if x[2] == 4:
    if s[1][1] > x[1]:
      s[1][1] = x[1]
      
if s[0][1] - s[0][0] < 0 or s[1][1] - s[1][0]:
  print(0)
else:
  print(s[0][1] - s[0][0] * s[1][1] - s[1][0])

Submission status: Wrong Answer

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

for i in range(N):
  li.append(list(map(int,input().split())))

s = [[0, W], [0, H]]

for x in li:
  if x[2] == 1:
    if s[0][0] < x[0]:
      s[0][0] = x[0]
  
  if x[2] == 2:
    if s[0][1] > x[0]:
      s[0][1] = x[0]
  
  if x[2] == 3:
    if s[1][0] < x[1]:
      s[1][0] = x[1]
  
  if x[2] == 4:
    if s[1][1] > x[1]:
      s[1][1] = x[1]
      
if s[0][1] - s[0][0] < 0 or s[1][1] - s[1][0]:
  print(0)
else:
  print((abs(s[0][1] - s[0][0]) * abs(s[1][1] - s[1][0])))

Submission status: Wrong Answer

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

for i in range(N):
  li.append(list(map(int,input().split())))

s = [[0, W], [0, H]]

for x in li:
  if x[2] == 1:
    if s[0][0] < x[0]:
      s[0][0] = x[0]
  
  if x[2] == 2:
    if s[0][1] > x[0]:
      s[0][1] = x[0]
  
  if x[2] == 3:
    if s[1][0] < x[1]:
      s[1][0] = x[1]
  
  if x[2] == 4:
    if s[1][1] > x[1]:
      s[1][1] = x[1]

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

Submission status: Wrong Answer

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

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

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

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

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

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

print(max(0, ans_w*ans_h))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

xya = []

for _ in range(N):
    xya.append([int(i) for i in input().split()])

xmin = 0
ymin = 0
xmax = W
ymax = H

for i in xya:
    if i[2] == 1:
        xmin = max(xmin, i[0])
    elif i[2] == 2:
        xmax = min(xmax, i[0])
    elif i[2] == 3:
        ymin = max(ymin, i[1])
    else:
        ymax = min(ymax, i[1])

s = (xmax - xmin) * (ymax - ymin)

if s > 0:
    print(s)
else:
    print(0)

Submission status: Wrong Answer

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

xya = []

for _ in range(N):
    xya.append([int(i) for i in input().split()])

xmin = 0
ymin = 0
xmax = W
ymax = H

for i in xya:
    if i[2] == 1:
        xmin = max(xmin, i[0])
    elif i[2] == 2:
        xmax = min(xmax, i[0])
    elif i[2] == 3:
        ymin = max(ymin, i[1])
    else:
        ymax = min(ymax, i[1])

s = (xmax - xmin) * (ymax - ymin)

print(xmin, xmax, ymin, ymax)
if s > 0:
    print(s)
else:
    print(0)

Submission status: Wrong Answer

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

xya = []

for _ in range(N):
    xya.append([int(i) for i in input().split()])

xmin = 1
ymin = 1
xmax = W
ymax = H

for i in xya:
    if i[2] == 1:
        xmin = max(xmin, i[0])
    elif i[2] == 2:
        xmax = min(xmax, i[0])
    elif i[2] == 3:
        ymin = max(ymin, i[1])
    else:
        ymax = min(ymax, i[1])

s = (xmax - xmin) * (ymax - ymin)

if s > 0:
    print(s)
else:
    print(0)

Submission status: Wrong Answer

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

xya = []

for _ in range(N):
    xya.append([int(i) for i in input().split()])

xmin = 1
ymin = 1
xmax = W
ymax = H

for i in xya:
    if i[2] == 1:
        xmin = min(xmin, i[0])
    elif i[2] == 2:
        xmax = max(xmax, i[0])
    elif i[2] == 3:
        ymin = min(ymin, i[1])
    else:
        ymax = max(ymax, i[1])

s = (xmax - xmin) * (ymax - ymin)

if s > 0:
    print(s)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def check():
    W,H,N = map(int, input().split())
    start = [0,0]
    end = [W,H]
    
    for _ in range(N):
        x,y,a = map(int, input().split())
        if a == 1:
            start[0] = x
        elif a == 2:
            end[0] = x
        elif a == 3:
            start[1] = y
        else:
            end[1] = y

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

Submission status: Wrong Answer

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

xya = []

for _ in range(N):
    xya.append([int(i) for i in input().split()])

xmin = 1
ymin = 1
xmax = W
ymax = H

for i in xya:
    if i[2] == 1:
        xmin = i[0]
    elif i[2] == 2:
        xmax = i[0]
    elif i[2] == 3:
        ymin = i[1]
    else:
        ymax = i[1]

s = (xmax - xmin) * (ymax - ymin)
print(s)

Submission status: Wrong Answer

Solution code:
def check():
    W,H,N = map(int, input().split())
    start = [0,0]
    end = [W,H]
    
    for _ in range(N):
        x,y,a = map(int, input().split())
        if a == 1:
            start[0] = x
        elif a == 2:
            end[0] = x
        elif a == 3:
            start[1] = y
        else:
            end[1] = y
        if end[0] <= start[0] or end[1] <= start[1]:
            return 0
    return (end[0]-start[0])*(end[1]-start[1])

print(check())

Submission status: Wrong Answer

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

xya = []

for _ in range(N):
    xya.append([int(i) for i in input().split()])

xmin = 1
ymin = 1
xmax = W
ymax = H

for i in xya:
    if i[2] == 1:
        xmin = i[0]
    elif i[2] == 2:
        xmax = i[0]
    elif i[2] == 3:
        ymin = i[1]
    else:
        ymax = i[1]

s = (xmax - xmin) * (ymax - ymin)
if s > 0:
    print(s)
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(ans if ans > 0 else 0)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

print(max([0, (ex-sx)*(ey-sy)]))

Submission status: Wrong Answer

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

print((ex-sx)*(ey-sy))

Submission status: Wrong Answer

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

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

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

area = (x_two_min - x_one_max) * (y_four_min - y_three_max)
ans = max(0, int(area))
print(ans)

Submission status: Wrong Answer

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

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

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

area = (x_two_min - x_one_max) * (y_four_min - y_three_max)
ans = max(0, area)
print(ans)