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 collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')
mod = 10**9 + 7

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())


w,h,n = MI()
xya = LI(n)

xs,xe = 0,w
ys,ye = 0,h

for i in xya:
    x,y,a = i
    if a==1:
        xs = max(xs,x)
    elif a==2:
        xe = min(xe,x)
    elif a==3:
        ys = max(ys,y)
    elif a==4:
        ye = min(ye,y)

s = abs(xe-xs)*abs(ye-ys)
if s<0:
    print(0)
else:
    print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')
mod = 10**9 + 7

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())


w,h,n = MI()
xya = LI(n)

xs,xe = 0,w
ys,ye = 0,h

for i in xya:
    x,y,a = i
    if a==1:
        xs = max(xs,x)
    elif a==2:
        xe = min(xe,x)
    elif a==3:
        ys = max(ys,y)
    elif a==4:
        ye = min(ye,y)

s = (xe-xs)*(ye-ys)
if s<0:
    print(0)
else:
    print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')
mod = 10**9 + 7

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())


w,h,n = MI()
xya = LI(n)

xs,xe = 0,w
ys,ye = 0,h

for i in xya:
    x,y,a = i
    if a==1:
        xs = x
    elif a==2:
        xe = x
    elif a==3:
        ys = y
    elif a==4:
        ye = y
    else:
        print('E')

s = (xe-xs)*(ye-ys)
if s<0:
    print(0)
else:
    print(s)

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x1 = [0]
x2 = [w]
y1 = [0]
y2 = [h]

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

left = max(x1)
right = min(x2)
bottom = max(y1)
top = min(y2)

ans = (top - bottom) * (right - left)
print(ans if ans > 0 else 0)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
x1 = [0] #1 left border of white area
x2 = [w] #2
y1 = [0] #3
y2 = [h] #4

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

left = max(x1)
right = min(x2)
top = max(y1)
bottom = min(y2)


ans =(right-left)*(bottom - top)
if ans > 0:
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

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

xy = [0, W, 0, H]
judge = True
for n in range(N):
    x, y, a = map(int, input().split())
    a -= 1
    if not judge:
      continue
    elif a<=1:
        xy[a] = x
        if xy[0] >= xy[1]:
            judge = False
    else:
        xy[a] = y
        if xy[2] >= xy[3]:
            judge = False
area = (xy[1] - xy[0]) * (xy[3] - xy[2])
if not judge:
    area = 0
print(area)

Submission status: Wrong Answer

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

xy = [0, W, 0, H]
judge = True
for n in range(N):
    x, y, a = map(int, input().split())
    a -= 1
    if a<=1 and judge:
        xy[a] = x
        if xy[0] >= xy[1]:
            judge = False
    else:
        xy[a] = y
        if xy[2] >= xy[3]:
            judge = False
area = (xy[1] - xy[0]) * (xy[3] - xy[2])
if not judge:
    area = 0
print(area)

Submission status: Wrong Answer

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

xy = [0, W, 0, H]
judge = True
for n in range(N):
    x, y, a = map(int, input().split())
    a -= 1
    if a<=1:
        xy[a] = x
        if xy[0] >= xy[1]:
            judge = False
    else:
        xy[a] = y
        if xy[2] >= xy[3]:
            judge = False
area = (xy[1] - xy[0]) * (xy[3] - xy[2])
if not judge:
    area = 0
print(area)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xy = [0, W, 0, H]
for n in range(N):
    x, y, a = map(int, input().split())
    a -= 1
    if a<=1:
        xy[a] = x
    else:
        xy[a] = y
    
area = (xy[1] - xy[0]) * (xy[3] - xy[2])
if area < 0:
    area = 0
print(area)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
x1 = [0] #1 left border of white area
x2 = [w] #2
y1 = [0] #3
y2 = [h] #4
for i in range(n):
  x,y,a = map (int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y1.append(y)
  elif a ==4:
    y2.append(y)
left = max(x1)
right = min(x2)
bottom = max(y1)
top = min(y2)

ans =(right-left)*(top-bottom)
if ans > 0:
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s_w = [0, w]
s_h = [0, h]
for _ in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        s_w[0] = x
    elif a == 2:
        s_w[1] = x
    elif a == 3:
        s_h[0] = y
    elif a == 4:
        s_h[1] = y
if s_w[1] <= s_w[0] or s_h[1] <= s_h[0]:
    print(0)
else:
    print((s_w[1] - s_w[0]) * (s_h[1] - s_h[0]))

Submission status: Wrong Answer

Solution code:
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i - 1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n - m] * self.finv[m] % self.mod) % self.mod
        
def iparse():
    return list(map(int, input().split()))


if __name__ == "__main__":
    w, h, n = iparse()
    xmax = w
    xmin = 0
    ymin = 0
    ymax = h
    for i in range(n):
        x, y, a = iparse()
        
        if a == 1:
            xmin = x
        if a == 2:
            xmax = x
        if a == 3:
            ymin = y
        if a == 4:
            ymax = y
        
    print((max(xmax-xmin,0)*(max(0,ymax-ymin))))

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
sx,sy=0,0
for j in range(n):
    
    if A[j][2]==1 and sx<A[j][0]:
        sx=A[j][0]

    if A[j][2]==2 and w>A[j][0]:
        w=A[j][0]

    if A[j][2]==3 and sy<A[j][1]:
        sy=A[j][1]

    if A[j][2]==4 and h>A[j][1]:
        h=A[j][1]

if (w-sx)*(h-sy)<0:
    print(0)
else:
    print((w-sx)*(h-sy))

Submission status: Wrong Answer

Solution code:

url = "https://atcoder.jp//contests/abc047/tasks/abc047_b"

def main():
    w, h, n = list(map(int, input().split()))
    xya = [list(map(int, input().split())) for _ in range(n)]
    x, y = [0, w], [0, h]
    for low in xya:
        if low[2] == 1 and x[0] < low[0]:
            x[0] = low[0]
        elif low[2] == 2 and x[1] > low[0]:
            x[1] = low[0]
        elif low[2] == 3 and y[0] < low[1]:
            y[0] = low[1]
        elif low[2] == 4 and y[1] > low[1]:
            y[1] = low[1]
    xs = x[1] - x[0]
    ys = y[1] - y[0]
    if xs < 0 or ys < 0:
        print(9)
    else:
        ans = xs * ys
        print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(N):
    if a[i] == 1:
        w_s = x[i]
    elif a[i] == 2:
        w_e = x[i]
    elif a[i] == 3:
        h_s = y[i]
    else:
        h_e = y[i]

height = h_e - h_s
width = w_e - w_s

if height <= 0 or width <= 0:
    print(0)
else:
    print(height * width)

Submission status: Wrong Answer

Solution code:
def main():
    w, h, n = list(map(int, input().split()))
    xya = [list(map(int, input().split())) for _ in range(n)]
    x, y = [0, w], [0, h]
    for low in xya:
        if low[2] == 1:
            x[0] = low[0]
        elif low[2] == 2:
            x[1] = low[0]
        elif low[2] == 3:
            y[0] = low[1]
        elif low[2] == 4:
            y[1] = low[1]
    ans = (x[1] - x[0]) * (y[1] - y[0])
    print(ans) if ans >= 0 else print(0)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

max_x = 0
max_y = 0
min_x = W
min_y = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        max_x = max(max_x, x)
    elif a == 2:
        min_x = min(min_x, x)
    elif a == 3:
        max_y = max(max_y, y)
    else:
        min_y = min(min_y, y)

# print(max_x, max_y)
# print(min_x, min_y)
if((min_x - max_x) * (min_y - max_y)) > 0:
    print((min_x - max_x) * (min_y - max_y))
else:
    print(0)

Submission status: Wrong Answer

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

max_x = 0
max_y = 0
min_x = W
min_y = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        max_x = max(max_x, x)
    elif a == 2:
        min_x = min(min_x, x)
    elif a == 3:
        max_y = max(max_y, y)
    else:
        min_y = min(min_y, y)

# print(max_x, max_y)
# print(min_x, min_y)
if((min_x - max_x) * (min_y - max_y)) >= 0:
    print((min_x - max_x) * (min_y - max_y))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 63 B - すぬけ君の塗り絵 2 イージー
W,H,N = map(int,input().split())

X = []
Y = []
A = []
for _ in range(N):
    x,y,a = map(int,input().split())
    x -= 1;y -= 1
    X.append(x)
    Y.append(y)
    A.append(a)

mtrx = [['.']*W for _ in range(H)]

for a,(x,y) in zip(A,zip(X,Y)):
    if a == 1:
        for i in range(H):
            for j in range(x+1):
                mtrx[i][j] = '#'
    if a == 2:
        for i in range(H):
            for j in range(x+1,W):
                mtrx[i][j] = '#'
    if a == 3:
        for i in range(y+1):
            mtrx[i] = ['#']*W
    if a == 4:
        for i in range(y+1,H):
            mtrx[i] = ['#']*W
    for i in mtrx:
        print(i)      

ans = 0
for i in range(H):
    for j in range(W):
        if mtrx[i][j] == '.':
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
x1, x2, y1, y2 = 0, W, 0, 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)

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

Submission status: Wrong Answer

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

W, H, N = map(int, input().split())
xs = ys = 0
xe = W
ye = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        xs = x
    elif a == 2:
        xe = x
    elif a == 3:
        ys = y
    elif a == 4:
        ye = y

w = xe - xs
h = ye - ys
if w > 0 and h > 0:
    ans = w * h
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
w,h,n = map(int, input().split())
l,r,d,u = (0,w,0,h)
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:
    d = max(d,y)
  else:
    u = min(u,y)
print(max((r-l)*(u-d),0))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

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

    lx = 0
    rx = W
    uy = H
    dy = 0
    for i in range(N):
        if a[i] == 1:
            lx = max(lx, x[i])
        if a[i] == 2:
            rx = min(rx, x[i])
        if a[i] == 3:
            dy = max(dy, y[i])
        if a[i] == 4:
            uy = min(uy, y[i])
    ans = max(0, (rx - lx) * (uy - dy))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans=[0,W,0,H]

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

print(ans)
            
S=(ans[1]-ans[0])*(ans[3]-ans[2])  

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

Submission status: Wrong Answer

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

ans=[0,W,0,H]

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

            
S=(ans[1]-ans[0])*(ans[3]-ans[2])  

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

Submission status: Wrong Answer

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

ans=[0,W,0,H]

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

S=(ans[1]-ans[0])*(ans[3]-ans[2])  

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

Submission status: Wrong Answer

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

ans=[0,W,0,H]

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

S=(ans[1]-ans[0])*(ans[3]-ans[2])  

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
u, U, v, V = 0, W, 0, H

for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        u = max(u,x)
    if a == 2:
        U = min(U,x)
    if a == 3:
        v = max(v,y)
    if a == 4:
        V = min(V,y)

theta = lambda x:x if x > 0 else 0
print(theta((U-u)*(V-v)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
X_Y_A = [map(int, input().split()) for _ in range(N)]
oX = 0
oY = 0
for x, y, a in X_Y_A:
    if a == 1:
        oX = x
    elif a == 2:
        W = x
    elif a == 3:
        oY = y
    else:
        H = y
A = (W-oX)*(H-oY)
print(A) if A > 0 else print(0)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
max_x,min_x,max_y,min_y=w,0,h,0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    min_x=x
  elif a==2:
    max_x=x
  elif a==3:
    min_y=y
  elif a==4:
    max_y=y
print(max(0,max_x-min_x)*max(0,max_y-min_y))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3


def main():
    import numpy as np

    W, H, N = map(int, input().split())
    sq = np.ones((H + 1, W))
    for i in range(N):
        x, y, a = map(int, input().split())
        if a == 1:
            sq[:, :x] = 0
        elif a == 2:
            sq[:, x:] = 0
        elif a == 3:
            sq[:y, :] = 0
        else:
            sq[y:, :] = 0
    print(np.count_nonzero(sq))


main()

Submission status: Wrong Answer

Solution code:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


w, h, n = inintm()

ll = [0,0]
lh = [0,h]
rl = [w,0]
rh = [w,h]

for i in range(n):
    x, y, a = inintm()
    if a == 1:
        ll[0] = max(ll[0], x)
        lh[0] = max(lh[0], x)
    elif a == 2:
        rl[0] = min(rl[0], x)
        rh[0] = min(rh[0], x)
    elif a == 3:
        rl[1] = max(rl[1], y)
        ll[1] = max(ll[1], y)
    else:
        rh[1] = min(rh[1], y)
        lh[1] = min(lh[1], y)

print(max((rl[0]-ll[0])*(lh[1]-ll[1]), 0))

Submission status: Wrong Answer

Solution code:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


w, h, n = inintm()

ll = [0,0]
lh = [0,h]
rl = [w,0]
rh = [w,h]

for i in range(n):
    x, y, a = inintm()
    if a == 1:
        ll[0] = max(ll[0], x)
        lh[0] = max(lh[0], x)
    elif a == 2:
        rl[0] = min(rl[0], x)
        rh[0] = min(rh[0], x)
    elif a == 3:
        rl[1] = max(rl[1], y)
        ll[1] = max(ll[1], y)
    else:
        rh[1] = min(rh[1], y)
        lh[1] = min(lh[1], y)

print(min((rl[0]-ll[0])*(lh[1]-ll[1]), 0))

Submission status: Wrong Answer

Solution code:
W,H,N = map(int,input().split())
Ox,Oy = 0,0
Oxx,Oyy = 0,0
for i in range(N):
  x,y,a = map(int,input().split())
  if a ==1:
    Oxx = Ox + x
  elif a == 2:
    W = W - (W - x)
  elif a == 3:
    Oyy = Oy + y
  else:
    H = H - (H - y)

print((W-Oxx)*(H-Oyy) if (W-Oxx)*(H-Oyy) > 0 else "0")

Submission status: Wrong Answer

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

xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):

    if array[i][2] == 1:
        xmin = max(xmin, array[i][0])
    elif array[i][2] == 2:
        xmax = min(xmax, array[i][0])
    elif array[i][2] == 3:
        ymin = max(ymin, array[i][1])
    elif array[i][2] == 4:
        ymax = min(ymax, array[i][1])
area = (xmax-xmin)*(ymax-ymin)
if area <= 0:
    print(0)
else:
    print(area)

Submission status: Wrong Answer

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

xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):

    if array[i][2] == 1:
        if array[i][0] > xmin:
            xmin = array[i][0]
    elif array[i][2] == 2:
        if array[i][0] < xmax:
            xmax = array[i][0]
    elif array[i][2] == 3:
        if array[i][1] > ymin:
            ymin = array[i][1]
    elif array[i][2] == 4:
        if array[i][1] < ymax:
            ymax = array[i][1]
area = (xmax-xmin)*(ymax-ymin)
if area <= 0:
    print(0)
else:
    print(area)

Submission status: Wrong Answer

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

xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):

    if array[i][2] == 1:
        if array[i][0] > xmin:
            xmin = array[i][0]
    if array[i][2] == 2:
        if array[i][0] < xmax:
            xmax = array[i][0]
    if array[i][2] == 3:
        if array[i][1] > ymin:
            ymin = array[i][1]
    if array[i][2] == 4:
        if array[i][1] < ymax:
            ymax = array[i][1]
area = (xmax-xmin)*(ymax-ymin)
if area <= 0:
    print(0)
else:
    print(area)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc047/tasks/abc047_b

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

left = 0
right = w
bottom = 0
top = h

for _ in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        left = x
    elif a == 2:
        right = x
    elif a == 3:
        bottom = y
    elif a == 4:
        top = y

if top <= bottom or right <= left:
    print(0)
else:
    print((right - left) * (top - bottom))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#初期値
lx=0
ly=0
rx=w
ry=h


for i in range(n):
    x,y,a=map(int, input().split())
    
    if a==1:
        if lx<x:
            lx=x
    elif a==2:
        if rx>x:
            rx=x
            
    elif a==3:
        if ly<y:
            ly=y
    
    else:
        if ry>y:
            ry=y
            
ans=(rx-lx)*(ry-ly)

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