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:
W, H, N = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
L, R, U, D = 0, W, H, 0
for p in P:
  x, y, a = p
  if a == 1:
    L = x
  elif a == 2:
    R = x
  elif a == 3:
    D = y
  else:
    U = y
print(max(U-D, 0) * max(R-L, 0))

Submission status: Wrong Answer

Solution code:
def resolve():
    W, H, N = list(map(int, input().split()))
    # (0,0)(W,H)を含む交点のx,y座標リスト
    white_W_list = list(range(W+1))
    white_H_list = list(range(H+1))
    for i in range(N):
        x, y, a = list(map(int, input().split()))
        if a == 1:
            white_W_list = [j for j in white_W_list if j >= x]
        elif a == 2:
            white_W_list = [j for j in white_W_list if j <= x]
        elif a == 3:
            white_H_list = [j for j in white_H_list if j >= y]
        elif a == 4:
            white_H_list = [j for j in white_H_list if j <= y]
    width = len(white_W_list) - 1
    length = len(white_H_list) - 1
    if width > 1 and length > 1:
        area = width * length
        print(area)
    else:
        print(0)

resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w,h,n = map(int,input().split())
width = w*[1]
height = h*[1]

for _ in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    width[:x] = [0]
  elif a == 2:
    width[x:] = [0]
  elif a == 3:
    height[:y] = [0]
  else:
    height[y:] = [0]
 
print(width.count(1)*height.count(1))

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x1 = 0
y1 = 0
x2 = w
y2 = h
f = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x1 = x
    elif a == 2:
        x2 = x
    elif a == 3:
        y1 = y
    elif a == 4:
        y2 = y
    
    if x1 >= x2 or y1 >= y2 or x2 <= 0 or y2 <= 0:
        f = 1
if f:
    print("0")
else:
    print((x2-x1)*(y2-y1))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

W,H,N = LI()

s,t,u,v = 0,W,0,H
for i in range(N):
    x,y,a = LI()
    if a == 1:
        s = max(s,x)
    if a == 2:
        t = min(t,x)
    if a == 3:
        u = max(u,y)
    if a == 4:
        v = min(v,y)

print(max(0,(t-s)*(v-u)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

w,h,n = readInts()
xya = [readInts() for i in range(n)]

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

for x,y,a in xya:
  if a==1:
    xmin = x
  elif a==2:
    xmax = x
  elif a==3:
    ymin = y
  else:
    ymax = y

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

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
wx=[0]*w
hy=[0]*h
for i in range(n):
  x,y,a=map(int,input().split())
  x-=1
  y-=1
  if a==1:
    for j in range(x):
      wx[j]=1
  if a==2:
    for j in range(x,w):
      wx[j]=1
  if a==3:
    for j in range(y):
      hy[j]=1
  if a==4:
    for j in range(y,h):
      hy[j]=1
print(wx.count(0)*hy.count(0))

Submission status: Wrong Answer

Solution code:
#数学的に解く
w,h,n = map(int,input().split())
cnt = 0
X = 0
Y = 0
while(cnt < n):
    x,y,a = map(int,input().split())
    
    if(a == 1):
        X = max(X,x)
    elif(a == 2):
        w = min(w,x)
    elif(a == 3):
        Y = max(Y,y)
    elif(a == 4):
        h = min(h,y)
    #print(w,h,X,Y)
    cnt += 1
print(min(w-X,0)*min(h-Y,0))

Submission status: Wrong Answer

Solution code:
#バッファ使わない
w,h,n = map(int,input().split())
cnt = 0
X = 0
Y = 0
while(cnt < n):
    x,y,a = map(int,input().split())
    
    if(a == 1):
        X = max(X,x)
    elif(a == 2):
        w = min(w,x)
    elif(a == 3):
        Y = max(Y,y)
    elif(a == 4):
        h = min(h,y)
    #print(w,h,X,Y)
    cnt += 1
print(abs(w-X)*abs(h-Y))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
point_lst = [list(map(int, input().split())) for _ in range(N)]
x_1 = 0
x_2 = W
y_1 = 0
y_2 = H

for point in point_lst:
    if point[2] == 1:
        if point[0] > x_1:
            x_1 = point[0]

    elif point[2] == 2:
        if point[0] < x_2:
            x_2 = point[0]
    elif point[2] == 3:
        if point[1] > y_1:
            y_1 = point[1]
    else:
        if point[1] < y_2:
            y_2 = point[1]

ans = (x_2 - x_1)*(y_2 - y_1)
print(ans if ans >= 0 else 0)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
s=[[0]*(w+1)]*(h+1)
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        for j in range(h+1):
            for p in range(w+1):
                if p<=x:
                    s[j][p]=1
    if a==2:
        for j in range(h+1):
            for p in range(w+1):
                if p>=x:
                    s[j][p]=1
    if a==3:
        for j in range(h+1):
            if j<=y:
                s[j]=[1]*(w+1)
    if a==4:
        for j in range(h+1):
            if j>=y:
                s[j]=[1]*(w+1)
ans=0
for i in range(h+1):
    for j in range(w+1):
        if s[i][j]==0:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
w,h,n=map(int,input().split())
s=[[0]*(w+1)]*(h+1)
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        for j in range(h+1):
            for p in range(w+1):
                if p<=x:
                    s[j][p]=1
    if a==2:
        for j in range(h+1):
            for p in range(w+1):
                if p>=x:
                    s[j][p]=1
    if a==3:
        for j in range(h+1):
            if j>=y:
                s[j]=[1]*(w+1)
    if a==4:
        for j in range(h+1):
            if j>=y:
                s[j]=[1]*(w+1)
ans=0
for i in range(h+1):
    for j in range(w+1):
        if s[i][j]==0:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input().split()

w = int(s[0])
h = int(s[1])
n = int(s[2])

max_x = w
max_y = h
min_x = 0
min_y = 0

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

for num in range(n):
    v = input().split()
    x.append(int(v[0]))
    y.append(int(v[1]))
    a.append(int(v[2]))

for num in range(n):
    if a[num] == 1:
        if x[num] > min_x:
            min_x = x[num]
    elif a[num] == 2:
        if x[num] < max_x:
            max_x = x[num]
    elif a[num] == 3:
        if y[num] > min_y:
            min_y = y[num]
    else:
        if y[num] < max_y:
            max_y = y[num]

y_length = max_y - min_y
x_length = max_x - min_x
answer = x_length * y_length
if answer < 0:
    answer = 0

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
# from decimal import Decimal
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

w, h, n = map(int, readline().split())
left = 0
right = w
up = h
down = 0

s = w * h
for i in range(n):
    x, y, a = map(int, readline().split())
    if (a == 1):
        left = x
    elif (a == 2):
        right = x
    elif (a == 3):
        down = y
    else:
        up = y

    if (right - left <= 0) or (up - down <= 0):
        print(0)
        exit()

ans = (right - left) * (up - down)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def nextrec(coor,pt):
    if coor[0]<=pt[0] and pt[0]<=coor[2] and coor[1]<=pt[1] and pt[1]<=coor[3]:
        if pt[2]==1:
            coor[0]=pt[0]
        elif pt[2]==2:
            coor[2]=pt[0]
        elif pt[2]==3:
            coor[1]=pt[1]
        elif pt[2]==4:
            coor[3]=pt[1]
        return False
    return True
def main(w,h,n,pts):
    rec=[0,0,w,h]
    for x in range(n):
        iszero = nextrec(rec, pts[x])
        if iszero:
          return 0
        
    return (rec[0]-rec[2])*(rec[1]-rec[3])

w,h,n=map(int,sys.stdin.readline().strip().split())
pts=[list(map(int,sys.stdin.readline().strip().split())) for x in range(n)]

print(main(w,h,n,pts))

Submission status: Wrong Answer

Solution code:
import sys

def nextrec(coor,pt):
    if coor[0]<=pt[0] and pt[0]<=coor[2] and coor[1]<=pt[1] and pt[1]<=coor[3]:
        if pt[2]==1:
            coor[0]=pt[0]
        elif pt[2]==2:
            coor[2]=pt[0]
        elif pt[2]==3:
            coor[1]=pt[1]
        elif pt[2]==4:
            coor[3]=pt[1]
def main(w,h,n,pts):
    rec=[0,0,w,h]
    for x in range(n):
        nextrec(rec, pts[x])
    return (rec[0]-rec[2])*(rec[1]-rec[3])

w,h,n=map(int,sys.stdin.readline().strip().split())
pts=[list(map(int,sys.stdin.readline().strip().split())) \
    for x in range(n)]

print(main(w,h,n,pts))

Submission status: Wrong Answer

Solution code:
import sys

def nextrec(coor,pt):
    if pt[2]==1:
        return [min(max(pt[0],coor[1]),coor[2]),coor[1],coor[2],coor[3]]
    elif pt[2]==2:
        return [coor[0],coor[1],max(min(pt[0],coor[2]),coor[0]),coor[3]]
    elif pt[2]==3:
        return [coor[0],min(coor[3],max(coor[1],pt[1])),coor[2],coor[3]]
    elif pt[2]==4:
        return [coor[0],coor[1],coor[2],max(coor[1],min(coor[3],pt[1]))]

def main(w,h,n,pts):
    rec=[0,0,w,h]
    for x in range(n):
        rec=nextrec(rec, pts[x])
    return (rec[0]-rec[2])*(rec[1]-rec[3])

w,h,n=map(int,sys.stdin.readline().strip().split())
pts=[list(map(int,sys.stdin.readline().strip().split())) \
    for x in range(n)]

print(main(w,h,n,pts))

Submission status: Wrong Answer

Solution code:
import sys

def nextrec(coor,pt):
    if (coor[0]-coor[2])*(coor[1]-coor[3])==0:
        return coor
    if pt[2]==1:
        return [min(pt[0],coor[2]),coor[1],coor[2],coor[3]]
    elif pt[2]==2:
        return [coor[0],coor[1],max(pt[0],coor[0]),coor[3]]
    elif pt[2]==3:
        return [coor[0],min(coor[3],pt[1]),coor[2],coor[3]]
    elif pt[2]==4:
        return [coor[0],coor[1],coor[2],max(coor[1],pt[1])]

def main(w,h,n,pts):
    rec=[0,0,w,h]
    for x in range(n):
        rec=nextrec(rec, pts[x])
    return (rec[0]-rec[2])*(rec[1]-rec[3])

w,h,n=map(int,sys.stdin.readline().strip().split())
pts=[list(map(int,sys.stdin.readline().strip().split())) \
    for x in range(n)]

print(main(w,h,n,pts))

Submission status: Wrong Answer

Solution code:
import sys

def nextrec(coor,pt):
    if pt[2]==1:
        return [min(pt[0],coor[2]),coor[1],coor[2],coor[3]]
    elif pt[2]==2:
        return [coor[0],coor[1],max(pt[0],coor[0]),coor[3]]
    elif pt[2]==3:
        return [coor[0],min(coor[3],pt[1]),coor[2],coor[3]]
    elif pt[2]==4:
        return [coor[0],coor[1],coor[2],max(coor[1],pt[1])]

def main(w,h,n,pts):
    rec=[0,0,w,h]
    for x in range(n):
        rec=nextrec(rec, pts[x])
    return (rec[0]-rec[2])*(rec[1]-rec[3])

w,h,n=map(int,sys.stdin.readline().strip().split())
pts=[list(map(int,sys.stdin.readline().strip().split())) \
    for x in range(n)]

print(main(w,h,n,pts))

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

w, h, n = rm()
xleft = 0
xright = w
ytop = h
ybottom = 0
for _ in range(n):
  x, y, a = rm()
  if a == 1:
    xleft = max(xleft, x)
  elif a == 2:
    xright = min(xright, x)
  elif a == 3:
    ytop = min(ytop, y)
  else:
    ybottom = max(ybottom, y)
if xleft >= xright or ybottom >= ytop:
  print(0)
else:
  print(w*h - (xright-xleft)*(ytop-ybottom))

Submission status: Wrong Answer

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

o,p,q,r = 0,0,0,0
for _ in range(n):
  x,y,a = map(int, input().split())
  if a == 1: o = max(o,x)
  elif a == 2: p = max(p,w-x)
  elif a == 3: q = max(q, y)
  elif a == 4: r = max(r,h-y)

w -= o+p
h -= q+r
if w*h >= 0: print(w*h)
else: print(0)

Submission status: Wrong Answer

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

nums = [-1]*4
nums[1] = 1000
nums[3] = 1000
for _ in range(n):
  x,y,a = map(int, input().split())
  if a == 1:
    if nums[0] < x: nums[0] = x
  elif a == 2:
    if nums[1] > x: nums[1] = x
  elif a == 3:
    if nums[2] < y: nums[2] = y
  elif a == 4:
    if nums[3] > y: nums[3] = y

for i in range(3,-1,-1):
  if nums[i] != 1000 and nums[i] != -1:
    if i == 3: h -= h - nums[3]
    elif i == 2: h -= nums[2]
    elif i == 1: w -= w - nums[1]
    elif i == 0: w -= nums[0] 
if w*h >= 0: print(w*h)
else: print(0)

Submission status: Wrong Answer

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

x_mx=w
x_mn=0
y_mx=h
y_mn=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        x_mn=max(x_mn,x)
    elif a==2:
        x_mx=min(x_mx,x)
    elif a==3:
        y_mn=max(y_mn,y)
    else:
        y_mx=min(y_mx,y)

ans=(x_mx-x_mn)*(y_mx-y_mn)
print(max(ans,0))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int,input().split())
x = 0
y = 0
a = 0
X = []
Y = []
A = []
for i in range(N):
    x, y, a = map(int,input().split())
    X.append(x)
    Y.append(y)
    A.append(a)
P = [[0 for i in range(W)] for j in range(H)]
for i in range(N):
    if A[i] == 1:
        for j in range(X[i]):
            for k in range(H):
                P[k][j] = 1
    elif A[i] == 2:
        for j in range(X[i],W):
            for k in range(H):
                P[k][j] = 1
    elif A[i] == 3:
        for j in range(Y[i]):
            for k in range(W):
                P[j][k] = 1
    elif A[i] == 4:
        for j in range(Y[i],H):
            for k in range(W):
                P[j][k] = 1
ans = 0
for i in range(W):
    for j in range(H):
        if P[j][i] == 0:
            ans += 1
print(P)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    W, H, N = il()
    w, h = 0, 0
    for _ in range(N):
        x, y, a = il()
        if a == 1 and w <= x:
            w = x
        if a == 2 and W >= x:
            W = x
        if a == 3 and h <= y:
            h = y
        if a == 4 and H >= y:
            H = y
    print(max((H - h) * (W - w), 0))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

x1 = 0
x2 = w
y1 = 0
y2 = 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)
    else:
        y2 = min(y2, y)

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

Submission status: Wrong Answer

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

x1 = 0
x2 = w
y1 = 0
y2 = h

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

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

Submission status: Wrong Answer

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

W,H,N = list(map(int,input().split()))
x0 = 0
y0 = 0
x1 = W
y1 = H

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

    if a == 1:
        x0 = max(x,x0)
    elif a == 2:
        x1 = min(x,x1)
    elif a == 3:
        y0 = max(y,y0)
    elif a == 4:
        y1 = min(y,y1)

print(max(0,(x1-x0)*(y1-y0)))

Submission status: Wrong Answer

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

W,H,N = list(map(int,input().split()))
x0 = 0
y0 = 0
x1 = W
y1 = H

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

    if a == 1:
        x0 = max(x,x0)
    elif a == 2:
        x1 = min(x,x1)
    elif a == 3:
        y0 = max(y,y0)
    elif a == 4:
        y1 = min(y,y1)
X = [x0,x1,y0,y1]

print(max(0,int((x1-x0)*(y1-y0))))

Submission status: Wrong Answer

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

W,H,N = list(map(int,input().split()))
x0 = 0
y0 = 0
x1 = W
y1 = H
X = [x0,x1,y0,y1]
for i in range(N):
    x,y,a = list(map(int,input().split()))

    if a == 1:
        x0 = max(x,x0)
    elif a == 2:
        x1 = min(x,x1)
    elif a == 3:
        y0 = max(y,y0)
    elif a == 4:
        y1 = min(y,y0)

print(max(0,int((x1-x0)*(y1-y0))))

Submission status: Wrong Answer

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

W,H,N = list(map(int,input().split()))
x0 = 0
y0 = 0
x1 = W
y1 = H
X = [x0,x1,y0,y1]
for i in range(N):
    x,y,a = list(map(int,input().split()))

    if a == 1:
        x0 = x
    elif a == 2:
        x1 = x
    elif a == 3:
        y0 = y
    elif a == 4:
        y1 = y

print(max(0,int((x1-x0)*(y1-y0))))

Submission status: Wrong Answer

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

W,H,N = list(map(int,input().split()))
x0 = 0
y0 = 0
x1 = W
y1 = H
X = [x0,x1,y0,y1]
for i in range(N):
    x,y,a = list(map(int,input().split()))

    if a == 1:
        x0 = x
    elif a == 2:
        x1 = x
    elif a == 3:
        y0 = y
    elif a == 4:
        y1 = y

print(max(0,(x1-x0)*(y1-y0)))

Submission status: Wrong Answer

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

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

for i in range(n):
    if a[i]==1:
        left=max(left, x[i])
    elif a[i]==2:
        right=min(right,x[i])
    elif a[i]==3:
        bottom=max(bottom,y[i])
    else:
        top=min(top,y[i])

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

Submission status: Wrong Answer

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

#print(W,H,N)
#print(lst)
#lst = sorted(lst, key=lambda x: x[2])
#print(lst)
Wst = [1]*W
Hst = [1]*H
for i in range(N):
    if lst[i][2] == 1:
        for j in range(lst[i][0]):
            Wst[j] = 0
    if lst[i][2] == 2:
        print(lst[i][0],W)
        for j in range(lst[i][0],W):
            Wst[j] = 0
    if lst[i][2] == 3:
        for j in range(lst[i][1]):
            Hst[j] = 0
    if lst[i][2] == 4:
        print(lst[i][0],W)
        for j in range(lst[i][1],H):
            Hst[j] = 0
    
#print(Wst,Hst)
print(sum(Wst)*sum(Hst))

Submission status: Wrong Answer

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

maxx = w
minx = 0
maxy = h
miny = 0

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        minx = x
    elif a == 2:
        maxx = x
    elif a == 3:
        miny = y
    else:
        maxy = y

ans = (maxx-minx)*(maxy-miny)
if minx > maxx or miny > maxy:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

maxx = w
minx = 0
maxy = h
miny = 0

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        minx = x
    elif a == 2:
        maxx = x
    elif a == 3:
        miny = y
    else:
        maxy = y

ans = (maxx-minx)*(maxy-miny)
print(max(0, ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    if num_w < x:
      num_w = x
  elif a == 2:
    if w > x:
      w = x
  elif a == 3:
    if num_h < y:
      num_h = y
  else:
    if h > y:
      h = y

ans = (w-num_w)*(h-num_h)
if ans < 0:
  print(0)
else:
  print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    if num_w < x:
      num_w = x
  elif a == 2:
    if w > x:
      w = x
  elif a == 3:
    if num_h < y:
      num_h = y
  else:
    if h > y:
      h = y
  
print((w-num_w)*(h-num_h))

Submission status: Wrong Answer

Solution code:
w,h,n=map(int, input().split())
x=[]
y=[]
a=[]
for i in range(n):
  s=input().split()
  x.append(int(s[0]))
  y.append(int(s[1]))
  a.append(int(s[2]))
x_l=0
x_h=w
y_l=0
y_h=h
for i in range(n):
  if a[i]==1:
    if x_l<x[i]:
      x_l=x[i]
  elif a[i]==2:
    if x_h>x[i]:
      x_h=x[i]
  elif a[i]==3:
    if y_l<y[i]:
      y_l=y[i]
  else:
    if y_h>y[i]:
      y_h=y[i]
s=(x_h-x_l)*(y_h-y_l)
if s>0:
  print(s)
else:
  print("0")

Submission status: Wrong Answer

Solution code:
def main():
    W, H, N = map(int, input().split())
    xl, xr, yb, yt = 0, W, 0, H
    for _ in range(N):
        x, y, a = map(int, input().split())
        if a == 1:
            xl = x
        elif a == 2:
            xr = x
        elif a == 3:
            yb = y
        elif a == 4:
            yt = y
    if xr-xl >= 0 and yt-yb >= 0:
        print((xr-xl)*(yt-yb))
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
w, h, n = map(int, input().split())
x = [[0 for i in range(3)] for j in range(n)]
p = [[0 for i in range(2)] for j in range(2)]
p[1][0], p[1][1] = w, h
for i in range(n):
  x[i][0], x[i][1], x[i][2] = map(int, input().split())

for i in range(n):
  if x[i][2] == 1:
    p[0][0] = x[i][0] if p[0][0] < x[i][0] else p[0][0]
  elif x[i][2] == 2:
    p[1][0] = x[i][0] if p[1][0] > x[i][0] else p[1][0]
  elif x[i][2] == 3:
    p[0][1] = x[i][1] if p[0][1] < x[i][1] else p[0][1]
  elif x[i][2] == 4:
    p[1][1] = x[i][1] if p[1][1] > x[i][1] else p[1][1]
print((p[1][0] - p[0][0]) * (p[1][1] - p[0][1]) if (p[1][0] - p[0][0]) * (p[1][1] - p[0][1]) > 0 else 0)

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#coding: utf-8
w, h, n = map(int,input().split())
x_low=0
x_high=w
y_low=0
y_high=h
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        x_low = max(x_low,x)
    if a == 2:
        x_high = min(x_high,x)
    if a == 3:
        y_low = max(y_low,y)
    if a == 4:
        y_high = min(y_high,y)
  
ans = (y_high-y_low)*(x_high-x_low)
print(max(ans,0))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xl, yl = 0, 0
xr, yr = W, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > xl:
            xl = x
    elif a == 2:
        if x < xr:
            xr = x

Submission status: Wrong Answer

Solution code:
#coding: utf-8
w, h, n = map(int,input().split())
x_ = w
y_ = h
x_low = 0
x_high = w
y_low = 0
y_high = h
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        if x_low < x:
            s = x-x_low
            x_ -= s
            x_low = x
    if a == 2:
        if x_high > x:
            s = x_high - x
            x_ -= s
            x_high = x
    if a == 3:
        if y_low < y:
            s = y-y_low
            y_ -= s
            y_low = y
    if a == 4:
        if y_high > y:
            s = y_high - y
            y_ -= s
            y_high = y
#print(x_,y_)
print(max(x_*y_,0))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
w, h, n = map(int,input().split())
X = [True] * (w+1)
Y = [True] * (h+1)
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        X[:x] = [False] * x
    if a == 2:
        X[x+1:] = [False] * (w-x+1)
    if a == 3:
        Y[:y] = [False] * y
    if a == 4:
        Y[y+1:] = [False] * (h-y+1)

ans = (X.count(True)-1) * (Y.count(True)-1)
print(max(ans,0))

Submission status: Wrong Answer

Solution code:
W, H, N = map(int, input().split())
xl, yl = 0, 0
xr, yr = W, H
S = W * H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
            xl = x
    elif a == 2:
            xr = x
    elif a == 3:
            yl = y
    elif a == 4:
            yr = y
    if xl >= xr or yl >= yr:
        print(0)
        exit()
print((xr - xl) * (yr - yl))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
w, h, n = map(int,input().split())
X = [True] * (w+1)
Y = [True] * (h+1)
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        X[:x] = [False] * x
    if a == 2:
        X[x+1:] = [False] * (w-x+1)
    if a == 3:
        Y[:y] = [False] * y
    if a == 4:
        Y[y+1:] = [False] * (h-y+1)

ans = (X.count(True)-1) * (Y.count(True)-1)
print(max(ans,0))