Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
1
Indexable
Never
class Solution:
    def internetCoverage(self, rng : int, N : int, wifi : List[List[int]]) -> bool:
        if rng==0: return False
        
        drn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
        drn2= [(-2,1),(-1,2),(1,2),(2,1),(2,-1),(1,-2),(-1,-2),(-2,-1)]
        drn3= [(-3,1),(-3,2),(-2,3),(-1,3),(3,1),(3,2),(2,3),(1,3),(-3,-1),(-3,-2),(-2,-3),(-1,-3),(3,-1),(3,-2),(2,-3),(1,-3)]
        wf = set()
        
        for i in range(N):
            for j in range(N):
                if wifi[i][j]: 
                    wf.add((i,j))
        if len(wf) == (N*N): return True
        wf2 = wf.copy()
        if rng == 1: return False
        for m,n in wf2:
            for i in range(1,rng):
                for a,b in drn:
                    x,y=m+(a*i),n+(b*i)
                    if x<0 or y<0 or x>=N or y>=N: continue
                    wf.add((x,y))
                if i == 2:
                    for a,b in drn2:
                        x,y=m+a,n+b
                        if x<0 or y<0 or x>=N or y>=N: continue
                        wf.add((x,y))
                if i == 3:
                    for a,b in drn3:
                        x,y=m+a,n+b
                        if x<0 or y<0 or x>=N or y>=N: continue
                        wf.add((x,y))
        if len(wf) == (N*N): return True
        else: 
            return False