Untitled
unknown
python
a year ago
1.6 kB
16
Indexable
n = int(input())
cows = set()
comfy_cows = set()
def check_comfy(cow):
neighbors = 0
x, y = cow
up = (x, y+1)
down = (x, y-1)
left = (x-1, y)
right = (x+1, y)
if up in cows:
neighbors += 1
if down in cows:
neighbors +=1
if left in cows:
neighbors += 1
if right in cows:
neighbors +=1
if neighbors == 3:
return True
else:
return False
c = 0
for _ in range(n):
s = input().split(" ")
x, y = int(s[0]), int(s[1])
cow = (x, y)
cows.add(cow)
if check_comfy(cow):
comfy_cows.add(cow)
up = (x, y+1)
down = (x, y-1)
left = (x-1, y)
right = (x+1, y)
if up in cows and up not in comfy_cows and check_comfy(up):
c += 1
comfy_cows.add(up)
if up in comfy_cows and not check_comfy(up):
c -= 1
comfy_cows.remove(up)
if down in cows and down not in comfy_cows and check_comfy(down):
c += 1
comfy_cows.add(down)
if down in comfy_cows and not check_comfy(down):
c -= 1
comfy_cows.remove(down)
if left in cows and left not in comfy_cows and check_comfy(left):
c += 1
comfy_cows.add(left)
if left in comfy_cows and not check_comfy(left):
c -= 1
comfy_cows.remove(left)
if right in cows and right not in comfy_cows and check_comfy(right):
c += 1
comfy_cows.add(right)
if right in comfy_cows and not check_comfy(right):
c -= 1
comfy_cows.remove(right)
print(c)Editor is loading...
Leave a Comment