Ah okay, I didn't think of that. Thanks!
Could I have some help making my code faster? It's in python. It seems to implement the same method as shown in the hints except with this one it doesn't have a 2D array that stores info on whether or not a point is valid.
# Get inputsN, M = map(int,input().split())grid = [[int(i) for i in input().split()]for j in range(N)]charms = [[*map(int,input().split())] for i in range(M)]dp = [[None for n in range(N)] for m in range(N)]dp = grid # Base casedef valid_square(coord, charms):# Checks to see if a square is validfor charm in charms:if abs(coord+1 - charm)+abs(coord+1 - charm) <= charm:return Truereturn Falsefor y in range(N):for x in range(N):